1
我想使用从Qt的上下文菜单,当我按右键单击。Qt按左键两次为上下文菜单消失
这里是我试过:
connect(mtreeView, SIGNAL(customContextMenuRequested(const QPoint&)),
this, SLOT(showContextMenu(const QPoint&)));
Then
void MainTreeViewController::showContextMenu(const QPoint& pos)
{
QPoint globalPos = mtreeView->mapToGlobal(pos);
QMenu rightClickMenu;
rightClickMenu.addAction(QString("Option"));
rightClickMenu.exec(globalPos);
}
当我按下右键,出现菜单,然后如果按住左键单击它外面没什么hapens。我必须按左键两次才能使菜单消失。
为什么会发生这种情况?谢谢!
你在哪里调用'menu.exec()'? – Amartel
已编辑,无法正常工作 – yonutix
您的代码看起来不错。你使用的是什么操作系统和Qt版本? – Amartel