Important: Please read the Qt Code of Conduct -

QMenu flickering when opened by touch

  • I'm encountering an issue where a QToolButton menu is being quickly hidden and redisplayed in response to the first touch update after being opened by a touch begin. Stepping into the Qt source, it appears that when the touch begin event is translated to the mouse event which opens the menu, the global mouse button state is never updated properly, causing the first touch update to produce an erroneous mouse button press event. I'm using Qt 5.2 on Android, but it appears that it would happen with touch input on any platform. I've tried an event filter to reject the erroneous events but encountered the additional problem that an immediate touch end with no touch update doesn't generate a mouse button release event. Can anyone suggest a possible workaround?

    Minimal example to reproduce below:

    #include <QtWidgets>

    // copy the following to
    // SOURCES = main.cpp
    // TARGET = QMenuTouchTest
    // QT += widgets

    class MainWindow : public QMainWindow
    MainWindow(QWidget* parent = 0) : QMainWindow(parent)
    QMenu* menu = new QMenu;
    menu->addAction("Item 1");
    menu->addAction("Item 2");
    menu->addAction("Item 3");
    QToolBar* toolbar = new QToolBar;
    QAction* action = toolbar->addAction("Menu");
    QToolButton* toolbtn = qobject_cast<QToolButton*>(toolbar->widgetForAction(action));
    setCentralWidget(new QLabel("QMenu Touch Test"));

    int main(int argc, char* argv[])
    QApplication app(argc, argv);
    MainWindow window;;
    return app.exec();

  • Just to follow up, reported here: and my workaround here:

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Thanks for sharing your findings and workaround !

Log in to reply