Results 1 to 2 of 2

Thread: State Transition when Mouse Enters Object Problem

  1. #1
    Join Date
    Mar 2012
    Posts
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default State Transition when Mouse Enters Object Problem

    I'm having a problem on transitioning between states, by hovering on the object.

    I have tried this code

    Qt Code:
    1. QStateMachine machine;
    2. machine.setGlobalRestorePolicy(QStateMachine::RestoreProperties);
    3.  
    4. QState *group = new QState(&machine);
    5. group->setObjectName("group");
    6.  
    7. QRect selectedRect(270, 125, 130, 130);
    8.  
    9. QState *idleState = new QState(group);
    10. group->setInitialState(idleState);
    11.  
    12. QObjectList objects;
    13. objects << p1 << p2 << p3;
    14.  
    15. QState *state1 = new QState(group);
    16. QState *state2 = new QState(group);
    17. QState *state3 = new QState(group);
    18.  
    19. state1->assignProperty(p1, "geometry", selectedRect);
    20. state2->assignProperty(p2, "geometry", selectedRect);
    21. state3->assignProperty(p3, "geometry", selectedRect);
    22.  
    23. // Enter P1
    24. QEventTransition *enterTransition = new QEventTransition(p1, QEvent::Enter);
    25. enterTransition->setTargetState(state1);
    26. group->addTransition(enterTransition);
    27.  
    28. // Enter P2
    29. QEventTransition *enterTransition = new QEventTransition(p2, QEvent::Enter);
    30. enterTransition->setTargetState(state2);
    31. group->addTransition(enterTransition);
    32.  
    33. // Enter P2
    34. QEventTransition *enterTransition = new QEventTransition(p3, QEvent::Enter);
    35. enterTransition->setTargetState(state3);
    36. group->addTransition(enterTransition);
    37.  
    38. window.createAnimations(objects, &machine);
    39.  
    40. machine.addState(s1);
    41. machine.addState(s2);
    42. machine.addState(s3);
    43. machine.setInitialState(group);
    44. machine.start();
    To copy to clipboard, switch view to plain text mode 

    It works fine if I try to trigger the transition with a mouse click,

    Qt Code:
    1. group->addTransition(p1, SIGNAL(clicked()), state1);
    To copy to clipboard, switch view to plain text mode 

    So I think I'm doing something wrong with the QEventTransition,
    but I have no idea what I'm doing wrong.

    Thanks.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: State Transition when Mouse Enters Object Problem

    Are your p1, p2 and p3 objects getting enter events at all? Use an event filter or reimplement the event handler to find out.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. How to write coding for state transition in qt qml?
    By harish in forum Qt Programming
    Replies: 0
    Last Post: 19th January 2012, 07:27
  2. Replies: 0
    Last Post: 28th June 2011, 07:41
  3. Replies: 1
    Last Post: 9th December 2010, 12:53
  4. Replies: 2
    Last Post: 16th November 2010, 06:11
  5. Replies: 1
    Last Post: 7th August 2010, 22:38

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.