QAction *pTest1 = new QAction(QIcon("copy.ico"),"复制", this)
QAction *pTest2 = new QAction("删除", this)
QAction *pTest3 = new QAction("标记", this)
QAction *pTest4 = new QAction("取消标记", this)
pMenu->addAction(pTest1)
pMenu->addAction(pTest2)
pMenu->addAction(pTest3)
pMenu->addAction(pTest4)
//添加分隔线
//pMenu->addSeparator()
//设置点击后发送的数据
// pTest1->setData(1)
//连接鼠标右键点击信号
connect(pTest1, &QAction::triggered, this, &sub::ClickCopy)
connect(pTest2, &QAction::triggered, this, &sub::ClickDel)
connect(pTest3, &QAction::triggered, this, &sub::Clicktink)
connect(pTest4, &QAction::triggered, this, &sub::ClickDeltink)
//在鼠标右键点击的地方显示菜单
pMenu->exec(cursor().pos())
//释放内存,若此处不手动释放,则必须等到程序结束时才都能释放
QList list = pMenu->actions()
foreach (QAction* pAction, list)
delete pAction
delete pMenu
不解释,自己看。// myWidget is any QWidget-derived class
myWidget->setContextMenuPolicy(Qt::CustomContextMenu)
connect(myWidget, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(ShowContextMenu(const QPoint&)))
void MyClass::ShowContextMenu(const QPoint& pos) // this is a slot
{
// for most widgets
QPoint globalPos = myWidget->mapToGlobal(pos)
// for QAbstractScrollArea and derived classes you would use:
// QPoint globalPos = myWidget->viewport()->mapToGlobal(pos)
QMenu myMenu
myMenu.addAction("Menu Item 1")
// ...
QAction* selectedItem = myMenu.exec(globalPos)
if (selectedItem)
{
// something was chosen, do stuff
}
else
{
// nothing was chosen
}
}
材料/工具:win7
1、下载、安装一个优化软件,启动应用程序,点击进入系统设置按钮选项
2、我们点击左侧的:右键菜单;
3、我们再点右上角的:添加鼠标右键菜单项目;
4、在打开的窗口中,我们可以看到,有18项菜单可以添加到鼠标右键,在我们要添加的项目前面打勾再点:应用到系统就可以了。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)