Qt 中的动画图像替换
我正在尝试在 QLabel 内对 QPixmap 的变化进行动画处理。
我有 MainWindow,它包含几个从 QScrollArea 派生的对象。其中每个都拥有一个 QLabel 成员。
使用mousePressEvent()
,我可以使用setPixmap()
替换每个QLabel的图片。然而,这只是切换每个 QLabel 中的图像,而我想要实现的是新图像在现有图像上滑动的动画。
首先,我尝试使用 QTimeLine 自己在 QLabel 上绘制 QPixmap(我为此创建了一个从 QLabel 派生的类,并编写了我自己的 setPixmap()),但这不起作用。接下来,我尝试使用 QPropertyAnimation,但如果我不为其实现子类,它就无法在 Pixmap 上构建。
任何想法或想法都值得赞赏。
I'm trying to animate the change of a QPixmap, inside QLabel.
I have MainWindow which holds several objects that derive from QScrollArea. Each of these holds a QLabel member.
Using mousePressEvent()
I am able to replace the picture of each QLabel using setPixmap()
. However, that simply switches the image in each QLabel, while what I would like to achieve is an animation where a new image slides over the existing one.
First I tried using a QTimeLine to draw the QPixmap on the QLabel myself (I've created a class that derives from QLabel for that, and wrote my own setPixmap()) but that didn't work. Next I tried using QPropertyAnimation but it can't construct on a Pixmap without me implementing a sub class for that as well.
Any thoughts or ideas are appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您将需要一个具有可动画属性的 QObject,并生成动画的中间帧。一个不完整的例子:
You will need a QObject with a property that can be animated, and generates the intermediate frames for the animation. An incomplete example:
QLabel 从未设计用于此类用途。在 QGraphicsView 中绘制 QPixmap,它更专注于渲染效果和动画。
QLabel was never designed for such uses. Draw your QPixmaps inside a QGraphicsView, it is far more focused towards rendering effects and animations.