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. QPropertyAnimation moves the window while it shouldn't

QPropertyAnimation moves the window while it shouldn't

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 3.2k 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.
  • A Offline
    A Offline
    alexandros
    wrote on last edited by
    #1

    Hi.
    I am using this:

    @
    animation = new QPropertyAnimation(this, "geometry");
    @
    so as to create a variable called animation, and on a button click I do this:
    @
    animation->setDuration(150);
    animation->setStartValue(QRect(preferences::x(), preferences::y(), width, window_height_min));
    animation->setEndValue(QRect(preferences::x(), preferences::y(), width, window_height_min+expand_general_to));
    animation->start();
    @
    The resize I do works just fine (as you can see, I just change the height of the window) but the window also instantly moves!
    If I press the button, preferences::x/y() doesn't return the correct values, apparently, but then, why is there an instant move of the window (it doesn't go to the specified location 'animately', smoothly, or whatever this is called)

    I can ensure you that there isn't any other function called that could cause this movement of the mainwindow. Also, if I change the value and do something like this:
    @
    animation->setStartValue(QRect(preferences::x()+9, preferences::y()+4, width, window_height_min));
    animation->setEndValue(QRect(preferences::x()+9, preferences::y()+4, width, window_height_min+expand_general_to));
    @
    then it works fine, unfortunately on GNOME, because on Plasma the values that have to be placed are different.

    How can I fix this? The problem is simple words is that I want only to resize smoothly the window, using a simple animation, but the window also moves!

    Thanks a lot for any answers in advance!

    1 Reply Last reply
    0
    • C Offline
      C Offline
      ChrisW67
      wrote on last edited by
      #2

      A simple example behaves as expected here (KDE 4.8, QT 4.8.1):
      @
      #include <QtGui>
      int main(int argc, char **argv)
      {
      QApplication app(argc, argv);
      QWidget w;
      w.setGeometry(QRect(100, 100, 100, 100));
      w.show();

      QPropertyAnimation anim(&w ,"geometry");
      anim.setDuration(5000);
      anim.setEndValue(QRect(100, 100, 200, 200));
      anim.start();
      
      return app.exec&#40;&#41;;
      

      }
      @

      If the window is moving then preferences:x() and ::y() would be the obvious candidates to scrutinise. If their value is not the same as the x,y position of the window at the start of the animation there will be an initial jump. Your window manager might also move the window if its geometry becomes unacceptable by whatever rules it uses.

      edit: Removed a bit about preferences::x() and ::y() changing over time because it was irrelevant.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        alexandros
        wrote on last edited by
        #3

        But.... I really don't get why my window moves itself... What should be the correct code so as to:
        Resize a Window using an animation ? Just resizing it to a specific size, by not altering the value of its position!

        1 Reply Last reply
        0
        • A Offline
          A Offline
          alexandros
          wrote on last edited by
          #4

          The correct answer is:
          @animation = new QPropertyAnimation(this, "size");
          animation->setDuration(150);
          animation->setStartValue(QSize(width, window_height_min));
          animation->setEndValue(QSize(width, window_height_min+expand_general_to));
          animation->start();@

          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