This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Using QMouseEventTransition

Tags: None
(comma "," separated)
User avatar
kernco
Registered Member
Posts
29
Karma
0
OS

Using QMouseEventTransition

Mon Dec 14, 2009 6:07 pm
This is more a Qt question than KDE. I'm using the new state machine framework in Qt 4.6, and I'm having some trouble with the QMouseEventTransition class. As I understand it, this is supposed to set up a transition so that the state machine moves to a state if the specified object is sent the mouse event that you give it. I haven't been able to get this to work. I've achieved the same functionality by just reimplementing the mouse event handlers in my class and emitting a signal, then setting up state machine transitions for those signals. I want to get it working with QMouseEventTransition, though, because it results in smaller code that's more understandable. Here is the relevant code from the class's constructor:
Code: Select all
setAcceptHoverEvents(true);

machine_ = new QStateMachine();
QState *idle = new QState();
QState *hovering = new QState();
idle->assignProperty(this, "scale", 1.0);
QMouseEventTransition *hoverEnter = new QMouseEventTransition(this, QEvent::HoverEnter, Qt::NoButton, idle);
hoverEnter->setTargetState(hovering);
idle->addTransition(hoverEnter);

hovering->assignProperty(this, "scale", 1.1);
QMouseEventTransition *hoverLeave = new QMouseEventTransition(this, QEvent::HoverLeave, Qt::NoButton, hovering);
hoverLeave->setTargetState(idle);
hovering->addTransition(hoverLeave);

machine_->addState(idle);
machine_->addState(hovering);
machine_->setInitialState(idle);
machine_->start();

Nothing happens when I hover over this QGraphicsWidget subclass, when I want it to scale bigger when that happens. I can uncomment my reimplementations of the hover events and replace those mouse event transitions with signal ones and it works fine. Does anyone know what the problem is?
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS

Re: Using QMouseEventTransition

Mon Dec 14, 2009 10:18 pm
I can't see any connections between the state machine and the QGraphicsWidget....
See http://qt.nokia.com/doc/4.6-snapshot/qs ... Transition

You need to "trigger" the state machine to change by using the SIGNAL variants, as shown in the simple example here: http://qt.nokia.com/doc/4.6-snapshot/st ... e-api.html


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
User avatar
kernco
Registered Member
Posts
29
Karma
0
OS

Re: Using QMouseEventTransition

Mon Dec 14, 2009 10:29 pm
bcooksley wrote:I can't see any connections between the state machine and the QGraphicsWidget....
See http://qt.nokia.com/doc/4.6-snapshot/qs ... Transition

I'm not sure what you mean. What sort of connection are you looking for? QGraphicsWidget has properties, which can be set when states are entered, just like a QWidget or a QGraphicsItem.

You need to "trigger" the state machine to change by using the SIGNAL variants, as shown in the simple example here: http://qt.nokia.com/doc/4.6-snapshot/st ... e-api.html

From looking through the documentation for the state machine framework, it seems to me like there are multiple ways to trigger a change, one way is using signals as you've pointed out, another way is with events. Unfortunately, none of the examples provided use these kinds of transitions, which might imply that you have to use signals. But if signals are the only way, what is the function of the QEventTransition, QKeyEventTransition and QMouseEventTransition which are listed there in the state machine framework documentation?
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS

Re: Using QMouseEventTransition

Mon Dec 14, 2009 10:45 pm
Hmm. Didn't see that as the example provided by Qt doesn't go into using an event based engine.

Possibly try with QWidgets ( temporarily to test it )?


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]


Bookmarks



Who is online

Registered users: abc72656, Bing [Bot], daret, Google [Bot], Sogou [Bot], Yahoo [Bot]