Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QMouseEventTransition not working?
Qt 6.11 is out! See what's new in the release blog

QMouseEventTransition not working?

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 1.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MaciejPawlisz
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      MaciejPawlisz
      wrote on last edited by
      #2

      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
      @

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved