QMouseEventTransition not working?



  • Hey, I want to use QMouseEventTransition to switch states in my StateMachine. I am using Qt 4.7.4.0. Well to be honest I am using PySide, but I don't think it changes anything, because I have similar results using PyQt4, and also someone has similar problems using C++ (http://forum.kde.org/viewtopic.php?f=64&t=84499)
    Long story short, here is the code (I subclassed QMouseEventTransition only to print some debug)
    @from PySide.QtCore import *
    from PySide.QtGui import *
    class myTransition(QMouseEventTransition):
    def init(self,object,type,button,source=None):
    super(myTransition,self).init(object,type,button,source)
    def eventTest(self, event):
    if event.type()==QEvent.StateMachineWrapped:
    e=event.event()
    print e.type(),e.button(),e.scenePos(),self.hitTestPath().contains(e.scenePos()),super(myTransition,self).eventTest(event)
    return super(myTransition,self).eventTest(event)
    app = QApplication([])
    scene=QGraphicsScene()
    scene.setSceneRect(0,0,100,100)
    view=QGraphicsView(scene)
    machine = QStateMachine()
    state1=QState(machine)
    state2=QFinalState(machine)
    trans = myTransition(scene,QEvent.GraphicsSceneMousePress,Qt.LeftButton,state1)
    trans.setTargetState(state2)
    path=QPainterPath()
    path.addRect(scene.sceneRect())
    trans.setHitTestPath(path)
    state1.addTransition(trans)
    machine.setInitialState(state1)
    machine.finished.connect(app.exit)
    machine.start()
    view.show()
    app.exec_()
    @
    Window pops up, and when I click in it in my opinion application should exit, or at least transition should be triggered. Unfortunately I only get my debug line:
    @
    PySide.QtCore.QEvent.Type.GraphicsSceneMousePress PySide.QtCore.Qt.MouseButton.LeftButton PySide.QtCore.QPointF(17.000000, 38.000000) True False
    @
    Everything in this event matches, and the transition should be triggered but it is not. Am I doing some kind of mistake or it is a bug?



  • Just to be clear, when in line 9 I change "e.scenePos()" to "e.pos()", I got:
    @
    PySide.QtCore.QEvent.Type.GraphicsSceneMousePress PySide.QtCore.Qt.MouseButton.LeftButton PySide.QtCore.QPointF(0.000000, 0.000000) True False
    @


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.