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

QScroller "stateChanged" event not triggered



  • In my application, I have a QGraphicsView in which I can scoll Items using the QScroller:

    self.graphicsScroller = QScroller()
    self.graphicsScroller.grabGesture(self.viewport(), self.graphicsScroller.TouchGesture)
    

    This works pretty well. However, if I want to subscribe to the stateChanged event:

    self.graphicsScroller.stateChanged.connect(self.scrollerStateChanged)
    

    To trigger the scrollerStateChanged method:

    @Slot(QScroller.State)
    def scrollerStateChanged(self, newState):
            print("scroller state changed")
    

    This doesn't work.

    I already tried the more convenient way by using QScroller without local reference:

    QScroller.grabGesture(self.viewport(), QScroller.TouchGesture)
    QScroller.stateChanged.connect(self.scrollerStateChanged)
    

    Works for scrolling, but stateChanged event is not triggered.
    Additionally I tried with lambda expressions, but also no result.

    Am I'm missing something here?
    Thanks in advance for any help on this!


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    I haven't used that class but based on the class documentation, I would guess the code should be something like:

    QScroller.grabGesture(self.viewport(), QScroller.TouchGesture)
    scroller = QScroller.scroller(self.viewport())
    scroller.stateChanged.connect(self.scrollerStateChanged)
    


  • @SGaist
    Thanks a lot. Instantiation using

    QScroller.scroller(self.viewport) 
    

    did the trick!
    Sorry that I missed that.


Log in to reply