开发者

Best way to animate a circle moving around a screen in Qt?

If I wanted to, using Qt, simply have some circles move around in a white bo开发者_如何学Gox, or a graphic, what would be the best method of this?

Would I need to draw white/the graphic behind where the circle moved from every time? Is there a simple way of accomplishing this in Qt?


  1. Create QGraphicsView object to your widget and added a QGraphicsScene to view.
  2. Add a QGraphicsEllipseItem to scene
  3. Use QPropertyAnimation to change the "pos" property of the ellipse item.

If you need more advanced features, you can build your own animation class on QPropertyAnimation.

enjoy it:)

Update: You can read Qt's Next Generation UI for more information.


Subclass a QWidget. Start a timerEvent() to animate the positions of the circles, then call update() at the end to schedule a repaint of the widget. Override the widget's paintEvent() - in there you draw your background and circles, using a QPainter object. The Qt Assistant has examples of how to use QPainter.

Qt also has a new animation framework that may facilitate something like this, but I have not looked into it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜