2013-02-15 115 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