2013-02-15 83 views
0

我有QListWidget,我需要從一個點移動到另一個,但它必須慢,像動畫。你能幫我解決這個問題嗎?Qt C++緩慢移動QListWidget

+0

您是否已閱讀過Qt Animation框架? – divanov 2013-02-15 16:40:41

回答

1

您需要爲此使用Qt Animation framework。有很多樣品可供使用,所以你應該閱讀它。

你正在嘗試做可以QPropertyAnimation類來完成,通過動畫的QListWidgetgeometry屬性:

QPropertyAnimation animation(&lstWidget, "geometry"); //animate geometry property 
animation.setDuration(5000); // 5 seconds 
animation.setStartValue(QRect(50, 50, 100, 100)); // start value for geometry property 
animation.setEndValue(QRect(300, 300, 100, 100)); // end value for geometry property 

animation.start(); 

這會從(50,50)部件移動到(300,300)。您可以通過從lstWidget讀取geometry屬性來設置起始值,以開始從當前位置移動等。

+0

我試過了,但它不是動畫,只是跳到新的位置。當按下按鈕時,我需要運行這些代碼行。所有這些都是使用Qt Designer完成的。 – Alen 2013-02-15 16:53:45

+1

@Alen確保在退出該功能時不會刪除動畫對象。嘗試在堆上分配動畫('QPropertyAnimation * animation = new QPropertyAn ...')並調用'animation-> start()',或者將'animation'移動到您的類成員上,因爲您將一次又一次地使用它。 – 2013-02-15 17:04:15

+0

Hvala @Nemanja :) – Alen 2013-02-15 17:10:56