diff --git a/src/plugins/platforms/xcb/qxcbconnection.cpp b/src/plugins/platforms/xcb/qxcbconnection.cpp
index edfaf2b0156ce1e44c5d2c9eecdb20de7ca62e1f..669ef3a98e351716b080978068166df3c29a4391 100644
--- a/src/plugins/platforms/xcb/qxcbconnection.cpp
+++ b/src/plugins/platforms/xcb/qxcbconnection.cpp
@@ -1626,8 +1626,13 @@ bool QXcbConnection::compressEvent(xcb_generic_event_t *event, int currentIndex,
         if (!m_xi2Enabled)
             return false;
 
-        // compress XI_Motion
+        // compress XI_Motion, but not from tablet devices
         if (isXIType(event, m_xiOpCode, XI_Motion)) {
+#ifndef QT_NO_TABLETEVENT
+            xXIDeviceEvent *xdev = reinterpret_cast<xXIDeviceEvent *>(event);
+            if (const_cast<QXcbConnection *>(this)->tabletDataForDevice(xdev->sourceid))
+                return false;
+#endif // QT_NO_TABLETEVENT
             for (int j = nextIndex; j < eventqueue->size(); ++j) {
                 xcb_generic_event_t *next = eventqueue->at(j);
                 if (!isValid(next))
diff --git a/src/plugins/platforms/xcb/qxcbconnection.h b/src/plugins/platforms/xcb/qxcbconnection.h
index 7ba95887ffef484d8d3faff5226ce709f63c99a0..501da1ce7b9152b0ae668c36e5ca71a1b4aa8074 100644
--- a/src/plugins/platforms/xcb/qxcbconnection.h
+++ b/src/plugins/platforms/xcb/qxcbconnection.h
@@ -578,6 +578,7 @@ private:
     bool xi2HandleTabletEvent(void *event, TabletData *tabletData, QXcbWindowEventListener *eventListener);
     void xi2ReportTabletEvent(TabletData &tabletData, void *event);
     QVector<TabletData> m_tabletData;
+    TabletData *tabletDataForDevice(int id);
 #endif // !QT_NO_TABLETEVENT
     struct ScrollingDevice {
         ScrollingDevice() : deviceId(0), verticalIndex(0), horizontalIndex(0), orientations(0), legacyOrientations(0) { }
diff --git a/src/plugins/platforms/xcb/qxcbconnection_xi2.cpp b/src/plugins/platforms/xcb/qxcbconnection_xi2.cpp
index 9911afb11e31e3f66afb72520ce19095e90cffd8..025dde3dbbc68f4c6f44151ac961bcdaaf199803 100644
--- a/src/plugins/platforms/xcb/qxcbconnection_xi2.cpp
+++ b/src/plugins/platforms/xcb/qxcbconnection_xi2.cpp
@@ -113,7 +113,7 @@ void QXcbConnection::xi2SetupDevices()
         // Only non-master pointing devices are relevant here.
         if (devices[i].use != XISlavePointer)
             continue;
-        qCDebug(lcQpaXInputDevices) << "input device "<< devices[i].name;
+        qCDebug(lcQpaXInputDevices) << "input device " << devices[i].name << "ID" << devices[i].deviceid;
 #ifndef QT_NO_TABLETEVENT
         TabletData tabletData;
 #endif
@@ -530,12 +530,9 @@ void QXcbConnection::xi2HandleEvent(xcb_ge_event_t *event)
 
 #ifndef QT_NO_TABLETEVENT
     if (!xiEnterEvent) {
-        for (int i = 0; i < m_tabletData.count(); ++i) {
-            if (m_tabletData.at(i).deviceId == sourceDeviceId) {
-                if (xi2HandleTabletEvent(xiEvent, &m_tabletData[i], eventListener))
-                    return;
-            }
-        }
+        QXcbConnection::TabletData *tablet = tabletDataForDevice(sourceDeviceId);
+        if (tablet && xi2HandleTabletEvent(xiEvent, tablet, eventListener))
+            return;
     }
 #endif // QT_NO_TABLETEVENT
 
@@ -1198,6 +1195,16 @@ void QXcbConnection::xi2ReportTabletEvent(TabletData &tabletData, void *event)
                                               xTilt, yTilt, tangentialPressure,
                                               rotation, 0, tabletData.serialId);
 }
+
+QXcbConnection::TabletData *QXcbConnection::tabletDataForDevice(int id)
+{
+    for (int i = 0; i < m_tabletData.count(); ++i) {
+        if (m_tabletData.at(i).deviceId == id)
+            return &m_tabletData[i];
+    }
+    return Q_NULLPTR;
+}
+
 #endif // QT_NO_TABLETEVENT
 
 #endif // XCB_USE_XINPUT2