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. Simple animation not working
Qt 6.11 is out! See what's new in the release blog

Simple animation not working

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 5.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.
  • S Offline
    S Offline
    smck87
    wrote on last edited by
    #1

    Hello! I am learning animation framework. I try to work out simple program. Let's pretend that i have window. How can i animate width of this window?

    I try this code:
    @
    Window::Window(QWidget *parent)
    : QWidget(parent)
    {
    anim=new QPropertyAnimation(this,"width");
    anim->setEasingCurve(QEasingCurve::InOutBack);
    anim->setDuration(100);
    anim->setStartValue(300);
    anim->setEndValue(500);
    anim->setLoopCount(-1); // loop never ends
    anim->start();
    }
    @
    but get this message in application output:
    @
    Starting F:\dev\win\2dpaint-build-desktop\release\2dpaint.exe...
    QPropertyAnimation: you're trying to animate the non-writable property x of your QObject
    QPropertyAnimation: you're trying to animate the non-writable property x of your QObject
    F:\dev\win\2dpaint-build-desktop\release\2dpaint.exe exited with code 0
    @

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      The error message is quite clear: you cannot change the property width via the property system of QObject. If you look at "QWidget's property width":http://doc.qt.nokia.com/4.7/qwidget.html#width-prop you will see, that there is only a getter, not a setter.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        smck87
        wrote on last edited by
        #3

        Thanks! This one works perfect
        @
        anim=new QPropertyAnimation(this,"geometry");
        anim->setEasingCurve(QEasingCurve::OutInQuad);
        anim->setDuration(2000);
        anim->setStartValue(QRect(100,100,100,100));
        anim->setEndValue(QRect(150,150,300,200));
        anim->setLoopCount(-1);
        anim->start();
        @

        So if i have setter for property i can make animation. I have few more questions:

        1. If i inherit QObject and create my own class with some parameter (width for example) and create setter function, can i animate this parameter with animation framework?
        2. How can i create endless animation as a sequence of direct and reverse animation?
        1 Reply Last reply
        0
        • S Offline
          S Offline
          smck87
          wrote on last edited by
          #4

          I worked out second question:
          @
          anim=new QPropertyAnimation(this,"geometry");
          anim->setEasingCurve(QEasingCurve::OutInQuad);
          anim->setDuration(3500);
          anim->setStartValue(QRect(100,100,100,100));
          anim->setKeyValueAt(1.0/2.0,QRect(150,150,300,200));
          anim->setEndValue(QRect(100,100,100,100));
          anim->setLoopCount(-1);
          anim->start();
          @
          Now i want to understand animation of custom properties. So to animate them i need inherit QObject and declarate my properties using macro Q_PROPERTY, right?

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andre
            wrote on last edited by
            #5

            Try and see?

            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