Problems animating QGraphicsProxyWidget
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
Code:
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)
Code:
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
Re: Problems animating QGraphicsProxyWidget
Try using the windowOpacity property of the QPushButton instead of the opacity property of the QGraphicsProxyWidget.
Re: Problems animating QGraphicsProxyWidget
d_stranz thanks for your reply.
I already tried that property but it is not working. As far as I understand that property can only be used for top level widgets.
Added after 1 41 minutes:
I could fix the problem.
I do not need to pass a parent to the QPushButton when creating it.