Make QQuickWidget accept touch events
ClosedPublic

Authored by alvinhochun on May 8 2018, 4:43 PM.

Details

Summary

This fixes operating the touch docker and other QML parts with touchscreen when using Qt 5.9.4 or later LTS (upstream bug https://bugreports.qt.io/browse/QTBUG-66718).

However, with Qt 5.9.3 or earlier, as well as Qt 5.10.0, there is a possibility of two click events being triggered when performing a touchscreen click. I have observed this behaviour with a test program. The rotation and zoom buttons on the touch docker shows this too.

This is related to D10988

Diff Detail

Repository
R37 Krita
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
alvinhochun created this revision.May 8 2018, 4:43 PM
Restricted Application added a subscriber: woltherav. · View Herald TranscriptMay 8 2018, 4:43 PM
alvinhochun requested review of this revision.May 8 2018, 4:43 PM
alvinhochun edited the summary of this revision. (Show Details)
anthonyfieroni added a subscriber: anthonyfieroni.EditedMay 8 2018, 5:46 PM

You can make a runtime check for version

static const bool shouldSetAcceptTouchEvents = QVersionNumber::fromString(qVersion()) > QVersionNumber(5, 9, 3);
if (shouldSetAcceptTouchEvents) {
    quickWidget->setAttribute(Qt::WA_AcceptTouchEvents);
}
rempt accepted this revision.May 9 2018, 8:44 AM
rempt added a subscriber: rempt.

I wonder what the officially best code to check for a Qt version is... We usually do stuff like

#if QT_VERSION >= 0x050903

or

#if QT_VERSION >= QT_VERSION_CHECK(5, 9, 3)

in our existing code... I'm fine with the patch, though, and I'm not even sure we do need a version check, since setting the attribute doesn't hurt on older versions of Qt, does it?

This revision is now accepted and ready to land.May 9 2018, 8:44 AM

You can make a runtime check for version

static const bool shouldSetAcceptTouchEvents = QVersionNumber::fromString(qVersion()) > QVersionNumber(5, 9, 3);
if (shouldSetAcceptTouchEvents) {
    quickWidget->setAttribute(Qt::WA_AcceptTouchEvents);
}

I wonder what the officially best code to check for a Qt version is... We usually do stuff like

#if QT_VERSION >= 0x050903

or

#if QT_VERSION >= QT_VERSION_CHECK(5, 9, 3)

in our existing code...

They do different things... @anthonyfieroni's is a run-time check which will test the version of the Qt shared libraries that's loaded into the process, @rempt's are compile-time checks that checks the version of Qt that the source is compiled against. Since there is ABI compatibility, the run-time version need not to match the compiled version. It's not an issue with the Windows/Appimage/macOS builds, but can be an issue for Linux distribution packages.

I'm fine with the patch, though, and I'm not even sure we do need a version check, since setting the attribute doesn't hurt on older versions of Qt, does it?

It does hurt... touchscreen will trigger two click events - one for the actual touch events, and one for the synthesized mouse events because older version stripped the "synthesized from touch" flag when passing the event to QML through QQuickWidget.

alvinhochun edited the summary of this revision. (Show Details)

Added run-time version check for Qt 5.9.x where x > 3 and Qt 5.10.1 or above.

rempt accepted this revision.May 17 2018, 1:20 PM

That should be fine then :-)

This revision was automatically updated to reflect the committed changes.