2012-07-11 123 views
6

我有以下問題:我想調整一個窗口使用QPropertyAnimation,以便看起來不錯,但窗口也立即移動,而調整大小發生,而我不希望它,我只是想調整窗口的大小,而不是改變它的位置值。使用QPropertyAnimation調整窗口大小

所以,這裏是我的代碼:

animation = new QPropertyAnimation(this, "geometry"); 
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(); 

其中寬度和window_height_min和expand_general_to是我自己的變量,可以說有許多工作要做的大小調整的數量。但是,preferences :: x()和preferences :: y()真正處理我的窗口的位置,所以它爲什麼會移動,而prefereces :: x()將是相同的時間? (在開始和結束值)?

在此先感謝您的任何答案!

回答

8

請嘗試設置大小屬性。

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();