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. Animation problems
Forum Updated to NodeBB v4.3 + New Features

Animation problems

Scheduled Pinned Locked Moved General and Desktop
8 Posts 3 Posters 2.1k 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.
  • G Offline
    G Offline
    GrahamL
    wrote on last edited by
    #1

    Hi
    I am trying to animate the movement of one of my widgets
    I have a simple Qt app consists of a main window with a label (done in QDesigner)
    The code to move the label is
    @
    QPropertyAnimation animation(ui.label,"geometry");
    animation.setDuration(10000);
    animation.setStartValue(ui.label->rect());
    QRect end = QRect(ui.label->rect().x() - 10,ui.label->y() - 10,ui.label->rect().width(),ui.label->rect().height());
    animation.setEndValue(end);
    animation.start();
    @
    Now this does move the label but it is move instantly whereas I thought that by specifying a duration , this would be how long it took to do the animation.

    I would be grateful if some could explain what I am doing wrong

    Thanks

    1 Reply Last reply
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      instead of creating the animation on the stack you should create it on the heap and specify that the animation should delete itself once it is finished:
      @
      QPropertyAnimation *animation = new QPropertyAnimation(ui.label,"geometry");
      animation->setDuration(10000);
      animation->setStartValue(ui.label->rect());
      QRect end = QRect(ui.label->rect().x() - 10,ui.label->y() - 10,ui.label->rect().width(),ui.label->rect().height());
      animation->setEndValue(end);
      animation->start(QAbstractAnimation::DeleteWhenStopped);
      @

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • N Offline
        N Offline
        NicuPopescu
        wrote on last edited by
        #3

        or do it static:

        @static QPropertyAnimation animation(ui->pushButtonRadio, "geometry");@

        1 Reply Last reply
        0
        • raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          [quote author="NicuPopescu" date="1385392921"]or do it static:

          @static QPropertyAnimation animation(ui->pushButtonRadio, "geometry");@[/quote]
          i wouldn't do this, because it's a pitfall !!

          You do create a static QPropertyAnimation instance with a target object (of the first caller).
          So if you use 2 instances of the same widget and this code gets called, the second instance will operate on the target object of the first. And also it will become invalid when the first instance gets destroyed and thus it will crash.
          It would work if you don't specify the target object with the construction. But then you have absolutely no benefit from declaring it static ...

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          0
          • N Offline
            N Offline
            NicuPopescu
            wrote on last edited by
            #5

            bq. But then you have absolutely no benefit from declaring it static …
            except it will function :) ... this was on my purpose

            1 Reply Last reply
            0
            • raven-worxR Offline
              raven-worxR Offline
              raven-worx
              Moderators
              wrote on last edited by
              #6

              i never said that it won't work... i explained that it has drawbacks...
              You can write tons of stupid code that will work for a particular case but that shouldn't be the goal right?
              And declaring it static like you suggested will only work flawlessly if you use the animation in a single instance of the class.

              --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
              If you have a question please use the forum so others can benefit from the solution in the future

              1 Reply Last reply
              0
              • N Offline
                N Offline
                NicuPopescu
                wrote on last edited by
                #7

                pff!

                bq. I am trying to animate the movement of one of my widgets

                no many instances generic code in the context etc.

                as it was explained by you someone could think is the only solution for getting QPropertyAnimation working, by allocating on heap ... or better to explain why does QPropertyAnimation not work as local variable!? that would enrich us indeed

                1 Reply Last reply
                0
                • raven-worxR Offline
                  raven-worxR Offline
                  raven-worx
                  Moderators
                  wrote on last edited by
                  #8

                  and once more... hope you get it now:
                  [quote author="raven-worx" date="1385635372"]i never said that it won't work... i explained that it has drawbacks...[/quote]
                  hey i don't mind what anyone does in his code. It was an advice from me take it or leave it.

                  and btw. just by reading the line "I am trying to animate the movement of one of my widgets " you know the widget structure of his application? If he wants to animate a child-widget of a widget he could have instantiated multiple times?

                  --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                  If you have a question please use the forum so others can benefit from the solution in the future

                  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