Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] Problems animating QGraphicsProxyWidget
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Problems animating QGraphicsProxyWidget

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kalos
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • J Offline
      J Offline
      jys0224
      wrote on last edited by
      #2

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

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

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

      1 Reply Last reply
      0
      • K Offline
        K Offline
        kalos
        wrote on last edited by
        #3

        thank you very much jys0224!

        It seems that was the problem.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved