diff --git a/src/plugins/platforms/xcb/qxcbconnection.cpp b/src/plugins/platforms/xcb/qxcbconnection.cpp
index 29acf0e86d..c25a39ddb3 100644
--- a/src/plugins/platforms/xcb/qxcbconnection.cpp
+++ b/src/plugins/platforms/xcb/qxcbconnection.cpp
@@ -911,14 +911,26 @@ bool QXcbConnection::compressEvent(xcb_generic_event_t *event) const
         // compress XI_Motion
         if (isXIType(event, XCB_INPUT_MOTION)) {
 #if QT_CONFIG(tabletevent)
-            auto xdev = reinterpret_cast<xcb_input_motion_event_t *>(event);
-            if (!QCoreApplication::testAttribute(Qt::AA_CompressTabletEvents) &&
-                    const_cast<QXcbConnection *>(this)->tabletDataForDevice(xdev->sourceid))
+            auto inputMotionEvent = reinterpret_cast<xcb_input_motion_event_t *>(event);
+            bool isTabletEvent = const_cast<QXcbConnection *>(this)->tabletDataForDevice(inputMotionEvent->sourceid);
+            if (!QCoreApplication::testAttribute(Qt::AA_CompressTabletEvents) && isTabletEvent)
                 return false;
 #endif // QT_CONFIG(tabletevent)
+            ScrollingDevice *scrollingDevice = const_cast<QXcbConnection *>(this)->scrollingDeviceForId(inputMotionEvent->sourceid);
+            bool isScrollEvent = (scrollingDevice && const_cast<QXcbConnection *>(this)->xi2IsScrollEvent(event, *scrollingDevice));
             return m_eventQueue->peek(QXcbEventQueue::PeekRetainMatch,
-                                      [this](xcb_generic_event_t *next, int) {
-                return isXIType(next, XCB_INPUT_MOTION);
+                                      [this, isTabletEvent, scrollingDevice, isScrollEvent](xcb_generic_event_t *next, int) {
+                if (!isXIType(next, XCB_INPUT_MOTION))
+                    return false;
+                auto inputMotionNextEvent = reinterpret_cast<xcb_input_motion_event_t *>(next);
+#if QT_CONFIG(tabletevent)
+                bool isTabletNextEvent = const_cast<QXcbConnection *>(this)->tabletDataForDevice(inputMotionNextEvent->sourceid);
+                if (isTabletEvent != isTabletNextEvent)
+                    return false;
+#endif // QT_CONFIG(tabletevent)
+                ScrollingDevice *scrollingDeviceNext = const_cast<QXcbConnection *>(this)->scrollingDeviceForId(inputMotionNextEvent->sourceid);
+                bool isScrollNextEvent = (scrollingDeviceNext && const_cast<QXcbConnection *>(this)->xi2IsScrollEvent(next, *scrollingDeviceNext));
+                return scrollingDevice == scrollingDeviceNext && isScrollEvent == isScrollNextEvent;
             });
         }
 
diff --git a/src/plugins/platforms/xcb/qxcbconnection.h b/src/plugins/platforms/xcb/qxcbconnection.h
index 47036ca257..bbf908ea5b 100644
--- a/src/plugins/platforms/xcb/qxcbconnection.h
+++ b/src/plugins/platforms/xcb/qxcbconnection.h
@@ -326,6 +326,7 @@ private:
         QPointF lastScrollPosition;
     };
     QHash<int, ScrollingDevice> m_scrollingDevices;
+    bool xi2IsScrollEvent(void *event, ScrollingDevice &scrollingDevice);
     void xi2HandleScrollEvent(void *event, ScrollingDevice &scrollingDevice);
     void xi2UpdateScrollingDevice(ScrollingDevice &scrollingDevice);
     ScrollingDevice *scrollingDeviceForId(int id);
diff --git a/src/plugins/platforms/xcb/qxcbconnection_xi2.cpp b/src/plugins/platforms/xcb/qxcbconnection_xi2.cpp
index 04ddd3c98c..0ffcfeae7d 100644
--- a/src/plugins/platforms/xcb/qxcbconnection_xi2.cpp
+++ b/src/plugins/platforms/xcb/qxcbconnection_xi2.cpp
@@ -953,6 +953,39 @@ QXcbConnection::ScrollingDevice *QXcbConnection::scrollingDeviceForId(int id)
     return dev;
 }
 
+bool QXcbConnection::xi2IsScrollEvent(void *event, ScrollingDevice &scrollingDevice)
+{
+    auto *xiDeviceEvent = reinterpret_cast<qt_xcb_input_device_event_t *>(event);
+
+    if (xiDeviceEvent->event_type == XCB_INPUT_MOTION && scrollingDevice.orientations) {
+        if (platformWindowFromId(xiDeviceEvent->event)) {
+            double value;
+            if (scrollingDevice.orientations & Qt::Vertical) {
+                if (xi2GetValuatorValueIfSet(xiDeviceEvent, scrollingDevice.verticalIndex, &value))
+                    return true;
+            }
+            if (scrollingDevice.orientations & Qt::Horizontal) {
+                if (xi2GetValuatorValueIfSet(xiDeviceEvent, scrollingDevice.horizontalIndex, &value))
+                    return true;
+            }
+        }
+    } else if (xiDeviceEvent->event_type == XCB_INPUT_BUTTON_RELEASE && scrollingDevice.legacyOrientations) {
+        if (platformWindowFromId(xiDeviceEvent->event)) {
+            QPoint angleDelta;
+            if (scrollingDevice.legacyOrientations & Qt::Vertical) {
+                if (xiDeviceEvent->detail == 4 || xiDeviceEvent->detail == 5)
+                    return true;
+            }
+            if (scrollingDevice.legacyOrientations & Qt::Horizontal) {
+                if (xiDeviceEvent->detail == 6 || xiDeviceEvent->detail == 7)
+                    return true;
+            }
+        }
+    }
+
+    return false;
+}
+
 void QXcbConnection::xi2HandleScrollEvent(void *event, ScrollingDevice &scrollingDevice)
 {
     auto *xiDeviceEvent = reinterpret_cast<qt_xcb_input_device_event_t *>(event);
