[SOLVED] 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

    @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");



    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->setEndValue(QPointF(scene()->width()/2, scene()->height()/2));


    I'm using Qt 4.7.3
    Do you have any idea how to fix this issue?

    Thanks in advance,

  • i think, you should not give a parent object when creating QPushButton;

    myButton = new QPushButton();
    (not, myButton = new QPushButton(this);)

    embeded widget will be destroyed when proxy is being destructed (by QGraphicsProxyWidget documentation)

  • thank you very much jys0224!

    It seems that was the problem.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.