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 qmenutest.pro:
// SOURCES = main.cpp
// TARGET = QMenuTouchTest
// QT += widgetsclass MainWindow : public QMainWindow
{
public:
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");
action->setMenu(menu);
QToolButton* toolbtn = qobject_cast<QToolButton*>(toolbar->widgetForAction(action));
toolbtn->setPopupMode(QToolButton::InstantPopup);
addToolBar(toolbar);
setCentralWidget(new QLabel("QMenu Touch Test"));
}
};int main(int argc, char* argv[])
{
QApplication app(argc, argv);
MainWindow window;
window.show();
return app.exec();
}
@ -
Just to follow up, reported here: https://bugreports.qt-project.org/browse/QTBUG-35985 and my workaround here: https://github.com/pbsurf/touchwidgets
-
Hi and welcome to devnet,
Thanks for sharing your findings and workaround !