大佬教程收集整理的这篇文章主要介绍了c – 在Qt中右键单击事件以打开上下文菜单,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
void plotspace::mousePressEvent(QMouseEvent*event) { double trange = _timeonright - _timeonleft; int twidth = width(); double Tinterval = trange/twidth; int xclicked = event->x(); _xvaluecoordinate = _timeonleft+Tinterval*xclicked; double fmax = Data.plane(X,0).max(); double fmin = Data.plane(X,0).min(); double fmargin = (fmax-fmin)/40; int fheight = height(); double finterval = ((fmax-fmin)+4*fmargin)/fheight; int yclicked = event->y(); _yvaluecoordinate = (fmax+fmargin)-finterval*yclicked; cout<<"Time(s): "<<_xvaluecoordinate<<endl; cout<<"Flux: "<<_yvaluecoordinate<<endl; cout << "timeonleft= " << _timeonleft << "\n"; returncoordinates(); emit updateCoordinates(); if (event->button()==Qt::rightButton) { contextmenu->setContextmenupolicy(Qt::CustomcatontextMenu); connect(contextmenu,SIGNAL(customcatontextMenurequested(const QPoint&)),this,SLOT(ShowContextMenu(const QPoint&))); void A::ShowContextMenu(const QPoint &pos) { QMenu *menu = new QMenu; menu->addAction(tr("Remove Data Point"),SLOT(test_slot())); menu->exec(w->mapToGlobal(pos)); } } }
我知道我的问题本质上是非常根本的,而且“上下文菜单”没有被正确的声明.我从许多来源拼凑了这个代码,不知道如何在c中声明某些东西.任何建议将不胜感激.
this->setContextmenupolicy(Qt::CustomcatontextMenu); connect(this,SIGNAL(customcatontextMenurequested(const QPoint &)),SLOT(ShowContextMenu(const QPoint &)));
ShowContextMenu插槽应该是plotspace的类成员,如:
void plotspace::ShowContextMenu(const QPoint &pos) { QMenu contextMenu(tr("Context menu"),this); QAction action1("Remove Data Point",this); connect(&action1,SIGNAL(triggered()),SLOT(removeDataPoint())); contextMenu.addAction(&action1); contextMenu.exec(mapToGlobal(pos)); }
以上是大佬教程为你收集整理的c – 在Qt中右键单击事件以打开上下文菜单全部内容,希望文章能够帮你解决c – 在Qt中右键单击事件以打开上下文菜单所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。