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