Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Why does QScrollArea scroll on multi-touch even if nobody told it to?



  • I'm using a multi-touch monitor (EIZO DuraVision FDF2382WT) with Lubuntu 18.04. I have a QScrollArea with a QLabel as widget. The QLabel has a QPixmap. Touching it with two or more fingers scrolls the picture. Why does this happen? According to my understanding of the documentation QTouchEvent handling is opt-in, except for QWindows which always receive them.

    I've tried setting AA_SynthesizeMouseForUnhandledTouchEvents to False, setting WA_AcceptTouchEvents for the QScrollArea and QLabel to both True and False. I saw no changes. I've tried reimplementing QScrollArea.event, QScrollArea.scroll, QLabel.event and the scroll bar setValue to log the calls, but nothing is printed.

    import sys
    
    from PyQt5 import Qt
    
    qapp = Qt.QApplication(sys.argv)
    
    picture = Qt.QPixmap('picture.png')
    
    qlab = Qt.QLabel()
    qlab.setPixmap(picture)
    
    qsa = Qt.QScrollArea()
    qsa.setWidget(qlab)
    qsa.setGeometry(10, 30, 200, 200)
    qsa.show()
    
    sys.exit(qapp.exec_())
    

    I was expecting the picture to stay in place, instead it is dragged. Nothing happens when dragging with the mouse or with just one finger.



  • Finally I've solved this: it was gestures!
    I brutally disabled them with something like

    import sys
    
    from PyQt5 import Qt
    
    qapp = Qt.QApplication(sys.argv)
    
    picture = Qt.QPixmap('/home/bruno/Pictures/ABCDEFGH_red_on_green.png')
    
    qlab = Qt.QLabel()
    qlab.setPixmap(picture)
    
    MyScrollArea = Qt.QScrollArea
    
    def event(self, event):
        print('DEBUG: event type {}'.format(event.type()))
        if event.type() in (Qt.QEvent.Gesture, Qt.QEvent.GestureOverride):
            event.accept()
            return True
        else:
            return super(MyScrollArea, self).event(event)
    
    MyScrollArea.event = event
    
    qsa = MyScrollArea()
    qsa.setWidget(qlab)
    qsa.setGeometry(10, 30, 200, 200)
    qsa.show()
    
    sys.exit(qapp.exec_())
    


  • Finally I've solved this: it was gestures!
    I brutally disabled them with something like

    import sys
    
    from PyQt5 import Qt
    
    qapp = Qt.QApplication(sys.argv)
    
    picture = Qt.QPixmap('/home/bruno/Pictures/ABCDEFGH_red_on_green.png')
    
    qlab = Qt.QLabel()
    qlab.setPixmap(picture)
    
    MyScrollArea = Qt.QScrollArea
    
    def event(self, event):
        print('DEBUG: event type {}'.format(event.type()))
        if event.type() in (Qt.QEvent.Gesture, Qt.QEvent.GestureOverride):
            event.accept()
            return True
        else:
            return super(MyScrollArea, self).event(event)
    
    MyScrollArea.event = event
    
    qsa = MyScrollArea()
    qsa.setWidget(qlab)
    qsa.setGeometry(10, 30, 200, 200)
    qsa.show()
    
    sys.exit(qapp.exec_())
    

Log in to reply