我是 Qt 新手,遇到一些问题QWidget
回转。
我在 QLabel 中有一个 QPixmap。
我想要的是让它连续旋转 90 度。
I know QPropertyAnimation
我知道如何使用它,但我正在努力解决如何使用它来旋转QWidget
。有没有什么简单的方法来实现我的目标并旋转整个QLabel
or the QPixmap
里面有动画?
谢谢。
这是旋转的演示QLabel/QPixmap
带动画。
没有必要使用QPropertyAnimation
。因为没有旋转属性QLabel
or QPixmap
。如此使用QVariantAnimation
make QPixmap
作为动画旋转并使用QPixmap::转换 http://doc.qt.io/qt-5/qpixmap.html#transformed旋转它。如果你想很好地控制像素图的动画,强烈推荐QGraphicsPixmapItem http://doc.qt.io/archives/qt-4.8/qgraphicspixmapitem.html with QPropertyAnimation
class RotateMe : public QLabel {
Q_OBJECT
public:
explicit RotateMe(QWidget* parent = Q_NULLPTR) :
QLabel(parent),
pixmap(100, 100),
animation(new QVariantAnimation )
{
resize(200, 200);
pixmap.fill(Qt::red);
animation->setDuration(10000);
animation->setStartValue(0.0f);
animation->setEndValue(90.0f);
connect(animation, &QVariantAnimation::valueChanged, [=](const QVariant &value){
qDebug()<<value;
QTransform t;
t.rotate(value.toReal());
setPixmap(pixmap.transformed(t));
});
animation->start();
}
private:
QPixmap pixmap;
QVariantAnimation *animation;
};
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)