QPropertyAnimation moves the window while it shouldn't
-
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!
-
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();
}
@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.
-
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! -
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();@