kalos80
27th August 2012, 10:27
Hi All,
I'm trying to animate a push button I have in my scene.
I want the button to become visible with an animation when the mouse enters the scene (essentially gradually changing the opacity of the button from 0 to 1)
The QPropertyAnimation class seems to be exactly what I need but it is not working with QGraphicsProxyWidget.
This is the way I'm creating the button when I initialize the interface of the QGraphicsView
void MyQGraphicsView::buildInterface(){
....
myButton = new QPushButton(this); // myButton member QPushButton variable
myButtonProxy = scene()->addWidget(myButton); // myButtonProxy member QGraphicsProxyWidget variable
...
}
void MyQGraphicsView::enterEvent( QEvent * )
{
QPropertyAnimation *animation = new QPropertyAnimation(myButtonProxy, "opacity");
animation->setDuration(1000);
animation->setStartValue(0);
animation->setEndValue(1);
animation->start(QAbstractAnimation::DeleteWhenStopped);
}
The animation has no effect on the opacity of the button. I also tried for test to modify with an animation the position of the button. Well If I create the QPropertyAnimation using the proxy widget then the animation is not working, if I create it using the button itsself then the animation is working (see example below)
void MyQGraphicsView::enterEvent( QEvent * )
{
// QPropertyAnimation *animation = new QPropertyAnimation(myButtonProxy, "pos"); // DOES NOT WORK
QPropertyAnimation *animation = new QPropertyAnimation(myButton, "pos");
animation->setDuration(1000);
animation->setStartValue(QPointF(0,0));
animation->setEndValue(QPointF(scene()->width()/2, scene()->height()/2));
animation->start(QAbstractAnimation::DeleteWhenStopped);
}
I'm using Qt 4.7.3
Do you have any idea how to fix this issue?
Thanks in advance,
Calogero
I'm trying to animate a push button I have in my scene.
I want the button to become visible with an animation when the mouse enters the scene (essentially gradually changing the opacity of the button from 0 to 1)
The QPropertyAnimation class seems to be exactly what I need but it is not working with QGraphicsProxyWidget.
This is the way I'm creating the button when I initialize the interface of the QGraphicsView
void MyQGraphicsView::buildInterface(){
....
myButton = new QPushButton(this); // myButton member QPushButton variable
myButtonProxy = scene()->addWidget(myButton); // myButtonProxy member QGraphicsProxyWidget variable
...
}
void MyQGraphicsView::enterEvent( QEvent * )
{
QPropertyAnimation *animation = new QPropertyAnimation(myButtonProxy, "opacity");
animation->setDuration(1000);
animation->setStartValue(0);
animation->setEndValue(1);
animation->start(QAbstractAnimation::DeleteWhenStopped);
}
The animation has no effect on the opacity of the button. I also tried for test to modify with an animation the position of the button. Well If I create the QPropertyAnimation using the proxy widget then the animation is not working, if I create it using the button itsself then the animation is working (see example below)
void MyQGraphicsView::enterEvent( QEvent * )
{
// QPropertyAnimation *animation = new QPropertyAnimation(myButtonProxy, "pos"); // DOES NOT WORK
QPropertyAnimation *animation = new QPropertyAnimation(myButton, "pos");
animation->setDuration(1000);
animation->setStartValue(QPointF(0,0));
animation->setEndValue(QPointF(scene()->width()/2, scene()->height()/2));
animation->start(QAbstractAnimation::DeleteWhenStopped);
}
I'm using Qt 4.7.3
Do you have any idea how to fix this issue?
Thanks in advance,
Calogero