c++ - Requires 2 right clicks to switch context menus among items? -
code below #include <qtwidgets> #include <qglwidget> int main(int argc, char *argv[]) { qapplication a(argc, argv); qmainwindow w; w.setcentralwidget(new qglwidget(&w)); // w.setcentralwidget(new qwidget(&w)); qtreewidget* tree = new qtreewidget(&w); qtreewidgetitem* item0 = new qtreewidgetitem(tree, qstringlist("a")); qtreewidgetitem* item1 = new qtreewidgetitem(tree, qstringlist("b")); tree->setcontextmenupolicy(qt::customcontextmenu); qobject::connect(tree, &qtreeview::customcontextmenurequested, [](){ qmenu menu; menu.addaction("a"); menu.exec(qcursor::pos()); }); qdockwidget* dock = new qdockwidget("tree", &w); dock->setwidget(tree); w.adddockwidget(qt::leftdockwidgetarea, dock); w.show(); return a.exec(); } compile , run it. requires 2 right clicks switch context menus among items. however, if change qglwidget