QT 右键菜单
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了QT 右键菜单相关的知识,希望对你有一定的参考价值。
参考技术A QMenu *pMenu = new QMenu(this);QAction *pTest1 = new QAction(QIcon("copy.ico"),"复制", this);
QAction *pTest2 = new QAction("删除", this);
QAction *pTest3 = new QAction("标记", this);
QAction *pTest4 = new QAction("取消标记", this);
//把QAction对象添加到菜单上
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;
以上是关于QT 右键菜单的主要内容,如果未能解决你的问题,请参考以下文章