Requires 2 right clicks to switch context menus among items?



  • Code below with Qt 5.3.0 x64 opengl on windows 7

    @#include <QtWidgets>
    #include <QGLWidget>

    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);
    QMainWindow w;

    w.setCentralWidget(new QGLWidget(&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&#40;QCursor::pos(&#41;&#41;;
    }&#41;;
    
    QDockWidget* dock = new QDockWidget("Tree", &w&#41;;
    dock->setWidget(tree&#41;;
    w.addDockWidget(Qt::LeftDockWidgetArea, dock&#41;;
    
    w.show(&#41;;
    return a.exec(&#41;;
    

    }@

    Compile and run it. It requires 2 right clicks to switch context menus among items. However, if I change QGLWidget to QWidget. It is fine. 1 right click can switch context menus among items. Any bugs??? Thanks a lot.

    Some observations: Switch the positions of the tree and the GL widget is ok, i.e. set the tree as the central widget and GL Widget as the one in the dock.

    More findings. When the widow is maximized. The issue is gone. When the widow is aligned with the left-top corner of the desktop screen, the issue is also gone. Thus, I think the bug is a mis-calculation of the mouse position when mapping to/from different widgets with dock widgets involved.

    Hope to see it corrected in the next Qt release.


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    You should also add which version of Qt you are using as well as the OS you are running on



  • Thanks. Added. Qt 5.3.0 X64 OpenGL + Windows 7 64 bit


  • Lifetime Qt Champion

    Can you test the same thing with 5.3.1 ?

    I can't reproduce it on OS X



  • Try it on Qt5.3.1 widows 7 x64. Still has the same problem. :(


  • Lifetime Qt Champion

    You may have found something. You should check the "bug report system":http://bugreports.qt-project.org to see if it's something known. If not please consider opening a new report providing a minimal compilable project (your main + the corresponding pro file in a zip file)



  • More findings. When the widow is maximized. The issue is gone. When the widow is aligned with the left-top corner of the desktop screen, the issue is also gone. Thus, I think the bug is a mis-calculation of the mouse position when mapping to/from different widgets with dock widgets involved.

    Hope to see it corrected in the next Qt release.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.