Results 1 to 7 of 7

Thread: Help using QStateMachine

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,233
    Thanks
    303
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Help using QStateMachine

    I am trying to implement a state machine for handling a complex set of mouse and keyboard interactions with a graphical data plot. I have partially finished the state chart, and have more than 25 states defined so far. The types of interactions include zooming in and out, selecting, moving, and resizing objects, panning, etc. Nearly all of the transitions between states occur on mouse, key, or mouse wheel events. There are a few transitions which could be driven by external events (for example, a button or menu signal to transition between zoom and pan modes).

    I am having trouble understanding how to extract event information from transitions.

    For example, a mouse-based zoom operation involves 4 states: Idle, ZoomStart, ZoomTrack, and ZoomEnd. The transition from the Idle state into ZoomStart occurs when the left mouse button is pressed. The transition from ZoomStart to ZoomTrack occurs on mouse move, and from ZoomTrack to ZoomEnd on mouse up. On entry into each of the Zoom... states, I need to capture the mouse position.

    In the widget that owns the state machine, I can define Q_PROPERTY variables to hold the initial, current, and final positions, but how do I set them when the transition occurs? All of the examples I have seen for QState::assignProperty() use essentially a constant for the QVariant, not some value that changes dynamically like a mouse position.

    Should I derive custom QState classes and reimplement the QState:nEntry() method? Or should I connect to the QEventTransition::triggered() signals and somehow get back to the QEvent instance to pull out the data?

    It would seem this is a common problem, but I haven't found an example (or answer here on the forum) that addresses this issue.

    Can anyone give me some help, please? Simply a link to some example code would be sufficient. Thanks in advance.

    Edit: a secondary question - is it possible explicitly set up a transition from a state back into itself? For example, ZoomTrack needs to be re-entered each time the mouse moves so the current mouse position can be updated (and a new rubberband drawn). Can I add a transition from ZoomTrack to ZoomTrack on QEvent::MouseMove?
    Last edited by d_stranz; 7th October 2011 at 23:54.

Similar Threads

  1. Asynchronous loop with QStateMachine
    By QTie in forum Qt Programming
    Replies: 3
    Last Post: 1st June 2011, 07:43
  2. Aid on QStateMachine
    By giorgik in forum Qt Programming
    Replies: 1
    Last Post: 27th April 2010, 10:24
  3. QStateMachine
    By piotr.dobrogost in forum Qt Programming
    Replies: 3
    Last Post: 6th December 2009, 08:17
  4. QStateMachine, not getting entered()
    By jimiq in forum Qt Programming
    Replies: 10
    Last Post: 19th November 2009, 10:17
  5. QStateMachine and signals
    By rossm in forum Qt Programming
    Replies: 2
    Last Post: 26th March 2009, 10:43

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.