[Qt-interest] QMouseEventTransition
Colin Kern
colin.kern at gmail.com
Sun Dec 13 06:12:14 CET 2009
Hi everyone,
I'm having trouble figuring out how to use the QMouseEventTransition
class. I'm trying to create a widget that gets bigger when hovered
over, and then goes back to it's normal size when the mouse moves
away. I've gotten it working by implementing the hoverEnter and
hoverLeave event handlers. Now I'm trying to do the same thing using
a state machine instead, but I can't get it to work. Here's the
relevant code from my widget's constructor:
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();
Can anyone see what I'm doing wrong? I've commented out my
hoverEnterEvent and hoverLeaveEvent functions in the class, in case
reimplementing those functions would cause the events to never make it
to the state machine.
Thanks,
Colin
More information about the Qt-interest-old
mailing list