WARAugmentedRealityOneSenceCover QWidget 上右键弹出 菜单
时间: 2024-02-11 18:06:10 浏览: 28
您好!感谢您的提问。根据您的描述,我了解到您想在 QWidget 上添加右键菜单。下面是我给出的解决方案:
1. 为 QWidget 添加 contextMenuEvent 事件处理函数。
2. 在 contextMenuEvent 函数中创建菜单,并设置菜单项。
3. 调用菜单的 exec 函数显示菜单。
下面是示例代码:
```
void WARAugmentedRealityOneSenceCover::contextMenuEvent(QContextMenuEvent *event)
{
// 创建菜单
QMenu menu(this);
// 添加菜单项
QAction *action1 = menu.addAction("菜单项1");
QAction *action2 = menu.addAction("菜单项2");
QAction *action3 = menu.addAction("菜单项3");
// 显示菜单
QAction *selected = menu.exec(event->globalPos());
// 处理菜单项的触发事件
if (selected == action1) {
// 菜单项1被触发
} else if (selected == action2) {
// 菜单项2被触发
} else if (selected == action3) {
// 菜单项3被触发
}
}
```
这是一个简单的示例代码,您可以根据自己的需求进行调整。希望我的回答能够帮到您!
相关推荐
![txt](https://img-home.csdnimg.cn/images/20210720083642.png)
<input type="text" id="jdid" />
[removed]
d = new dTree('d');
d.add(0,-1,'My example tree');
d.add(1,0,'Node 1','examplea1.html');
d.add(2,0,'Node 2','examplea2.html');
d.add(3,1,'Node 1.1','examplea3.html');
[removed](d);
[removed]
<!--右键菜单的源-->
添加节点
修改节点
删除节点
</body>
[removed]
//所有div标签class为dTreeNode的绑定此右键菜单
$('div.dTreeNode').contextMenu('myMenu1', {
onContextMenu: function(e) {
document.getElementById("jdid").value=$(e.target).attr('id');
if ($(e.target).attr('id') == ''||!checkRate($(e.target).attr('id')))
return false;
else
return true;
},
onShowMenu: function(e, menu) {
return menu;
}
});
//所有class为gen的span标签都会绑定此右键菜单
$('span.gen').contextMenu('myMenu1',
{
onContextMenu: function(e) {
document.getElementById("jdid").value=$(e.target).attr('id');
if ($(e.target).attr('id') == ''||!checkRate($(e.target).attr('id')))
return false;
else
return true;
},
onShowMenu: function(e, menu) {
return menu;
}
});
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)