Globulus
10th August 2011, 12:25
Hello!
I want QLabel, that contains image, make image bigger on enterEvent,
and smaller on leaveEvent. (animate it by QPropertyAnimation and QStateMachine ). For this purposes I subclassed QLabel, just like this:
class MyLabel : public QLabel
{
Q_OBJECT
public:
MyLabel(QWidget * parent = 0);
~MyLabel();
protected slots:
virtual void enterEvent ( QEvent * event );
virtual void leaveEvent ( QEvent * event );
};
MyLabel::MyLabel(QWidget * parent) : QWidget(parent)
{
}
MyLabel::~MyLabel()
{
}
void MyLabel::enterEvent ( QEvent * event )
{
}
void MyLabel::leaveEvent ( QEvent * event )
{
}
But what next - have no idea...
Tried something like :
void MyLabel::enterEvent ( QEvent * event )
{
QPropertyAnimation *animation = new QPropertyAnimation(this, "geometry");
animation->setDuration(600);
animation->setStartValue(QRect(this->geometry().x(), this->geometry().y(), 64, 64));
animation->setEndValue(QRect(this->geometry().x(), this->geometry().y(), 128, 128));
animation->start();
}
But that is not the idea, because this->geometry().x() returns 0....
I want QLabel, that contains image, make image bigger on enterEvent,
and smaller on leaveEvent. (animate it by QPropertyAnimation and QStateMachine ). For this purposes I subclassed QLabel, just like this:
class MyLabel : public QLabel
{
Q_OBJECT
public:
MyLabel(QWidget * parent = 0);
~MyLabel();
protected slots:
virtual void enterEvent ( QEvent * event );
virtual void leaveEvent ( QEvent * event );
};
MyLabel::MyLabel(QWidget * parent) : QWidget(parent)
{
}
MyLabel::~MyLabel()
{
}
void MyLabel::enterEvent ( QEvent * event )
{
}
void MyLabel::leaveEvent ( QEvent * event )
{
}
But what next - have no idea...
Tried something like :
void MyLabel::enterEvent ( QEvent * event )
{
QPropertyAnimation *animation = new QPropertyAnimation(this, "geometry");
animation->setDuration(600);
animation->setStartValue(QRect(this->geometry().x(), this->geometry().y(), 64, 64));
animation->setEndValue(QRect(this->geometry().x(), this->geometry().y(), 128, 128));
animation->start();
}
But that is not the idea, because this->geometry().x() returns 0....