When the touch point is released, it triggers the menu item without moving the touch point
-
#include <QApplication>
#include <QWidget>
#include <QMenu>
#include <QDebug>
#include <QGuiApplication>
#include <QStyleHints>
#include <QContextMenuEvent>class DebugWidget : public QWidget {
public:
explicit DebugWidget(QWidget *parent = nullptr) : QWidget(parent) {
setContextMenuPolicy(Qt::CustomContextMenu);
connect(this, &QWidget::customContextMenuRequested, [this](const QPoint &pos){
QMenu menu(this);
for(int i = 0; i < 30; i++) {
QAction *action = menu.addAction(QString("Test %1").arg(i + 1));
connect(action, &QAction::triggered, [action]{
qWarning() << "Clicked action:" << action->text();
});
}
menu.exec(mapToGlobal(pos));
});
}protected:
void contextMenuEvent(QContextMenuEvent *event) override {
qWarning() << "Context menu triggered by:"
<< (event->reason() == QContextMenuEvent::Mouse ? "Mouse" : "Touch");
QWidget::contextMenuEvent(event);
}
};int main(int argc, char *argv[]) {
QApplication app(argc, argv);
DebugWidget w;
w.show();
return app.exec();
}This is my demo, the current scenario is like this:
- I use the Qt environment is 5.15, I call out the right-click menu by touch screen long press, when the touch screen area just in the right-click menu options, there will be a BUG, that is, when I release the touch screen, it will select the current position of the menu options, which will result in a similar “second click”, that is, when you release the touch point, it will trigger the menu item. That is, when I release the touch point, it will trigger the menu item. When using the mouse, when clicking the right mouse button to call out the menu, click not release the mouse to move to the right menu of the corresponding item area when you release the right button will also trigger triggerd, but due to the mouse to release the right button will not happen to overlap the location and menu options, is the need to move a little bit will be hover after triggerd, so there is nothing wrong with the use of the touchscreen, because the touchupdate update very often, so the finger touch screen slightly different strength will trigger the menu item hover, I feel this is not right.
- qt6.8, I also through the touch screen way long press call out the right-click menu, when the touch screen area happens to be in the right-click menu options, there is no such thing, because in qt6.8, the touch screen is pressed down, in the pop-up right-click menu in the case of moving, and will not trigger the menu item, need to lift the finger to release the first, and then go back to touch the click, the menu option will be responded to.
I would like to port this effect from qt6.8 to qt5, what updates have been made to the source code to accomplish this, and where should I start to port the patch?
https://codereview.qt-project.org/c/qt/qtbase/+/590205 Similar problem to this one, but I tried it and found it only fixes the situation when mousing around
-
Hi and welcome to devnet,
Which version of 5.15 are you using ?
On which platform ?
Based on the comment of the patch, it seems related to High DPI as week which has seen quite a lot of improvement so it might not be possible to backport all of the related work.