MouseArea doesn't emit clicked after pressed/released pair
-
Hi,
I'm experimenting with Wayland Compositor under Qt 5.14.1 on Embedded system with touch screen. I'm forwarding TouchEvents to one of two applications withsurface()->compositor()->defaultSeat()->sendTouchPointEvent(surface(), id, point, state);It works. But I noticed that - from time to time - one of buttons in 4 buttons row in one of applications doesn't response, not the same.
After adding handler to all possible signals - I've noticed that from time to time - pressed and released signals are emitted, but not clicked.
Fromqtdeclarative/src/quick/items/qquickmousearea.cppandsetPressedfunction analysis it looks like to emit clickedif (isclick && !d->longPress && !d->doubleClick){
As I sad - all handlers are logging, so I'm sure that no PressAndHold and DoubleClick are emitted.
What remains is content of isclick bool flag -bool isclick = wasPressed && p == false && dragged == false && d->hovered == true;
I'm sure that wasPressed is true and p is false (otherwise there wouldn't be pressed and released signals).
MouseEvent contains most of above mentioned parameters. isClick is false for Released events. Also hovered/containsMouse is false. Which is crazy, as hoverEnabled by default is false so hovered should be registered only on click.Due to size of code and amount of applications and their interactions - it's very difficult to produce minimal reproduction set.
I'm in pickle. How to explain lack of clicked signal? How to modify MouseArea to be sure that this signal is emitted (like block drag - which AFAIR is by default inactivate).
-
I've narrow the root cause. Between TouchBegin and TouchEnd send from touch screen there's strange MouseMove event (it doesn't show always). When I move finger on screen - there's plenty of TouchUpdate events which are then translated to MouseMove.
Yet, this single MouseMove right after TouchBegin has no TouchUpdate.
I logged source of event - for all MousePressed and MouseRelesed it's Qt::MouseEventSynthesizedByQt which is result of translating TouchBegin/TouchEnd/TouchUpdate to their Mouse equivalent.
This single MouseMove which makes so much problem has source Qt::MouseEventNotSynthesized. Which puzzles me a lot - as this means that event is received from Mouse device. Whole system is embedded, there's no Mouse device.
Furthermore - TouchBegin and TouchEnd has the same coordinates, but this MouseMove usually has coordinates (10+, 10+) bigger then original.
Right now I'm investigating Qt code for locations where QMouseEvent with MouseMove type could be generated.
There's no way to identify who's event sender by recipient. -
Mouse Events and Touch Event Synthesizing
QTouchEvent delivery is independent from that of QMouseEvent. The application flags Qt::AA_SynthesizeTouchForUnhandledMouseEvents and Qt::AA_SynthesizeMouseForUnhandledTouchEvents can be used to enable or disable automatic synthesizing of touch events to mouse events and mouse events to touch events.
https://doc.qt.io/qt-5/qtouchevent.html
Can you try these flags? I am using Qt 5.15.2 and had issues(no response of buttons) on touch screen as well.
-
System uses Wayland. For UI design reasons there're decision to move touch area (-12,-15) in reference to display area.
And ... from time to time Wayland provides Touch Event not translated. Which - by Qt internals - is recognized as moved.
As a solution I added evenFilter to problematic buttons withbool eventFilter(QObject *obj, QEvent *event) override { if (event->type() == QEvent::MouseMove) { QMouseEvent *ev = dynamic_cast<QMouseEvent*>(event); auto * quickItem = qobject_cast<QQuickItem*>(obj); if (quickItem && !quickItem->contains(ev->pos()) && ev->source() == Qt::MouseEventNotSynthesized && !ev->spontaneous()) { return true; } } return QObject::eventFilter(obj, event); }I could strengthen condition by adding test for touch point translation (like pos diff == (12,15)), but above solution works good enough.
Still, it's workaround.