【发布时间】:2017-11-03 19:25:57
【问题描述】:
我有 2 个类,一个 MainWindow,我们在 QGraphicsView 中绘制一个圆(打算成为一个按钮!),这要归功于另一个类。 MyCircle 类继承自 QObject 和 QGraphicsItem,因为我想做动画。
我的问题如下:
我的目标是首先在我的绘图上制作一个简单的动画:让它变小然后恢复到原始大小。所以我想我应该使用 QObject 类中已经存在的属性 geometry。
为此,我在 MainWindow.ccp 中编写
animationBoutonRondTaille = new QPropertyAnimation(roundButton, "geometry");
animationBoutonRondTaille->setDuration(1000);
animationBoutonRondTaille->setKeyValueAt(0, QRect(-100, -100, 200, 200));
animationBoutonRondTaille->setKeyValueAt(0.5, QRect(-80,-80,160,160));
animationBoutonRondTaille->setKeyValueAt(1, QRect(-100, -100, 200, 200));
animationBoutonRondTaille -> start();
如果我不包括
class MyCircle : public QObject, public QGraphicsItem
{
Q_OBJECT
Q_PROPERTY(QRect geometry READ geometry WRITE setGeometry)
/.../
}
我收到以下错误消息:
QPropertyAnimation: you're trying to animate a non-existing property geometry of your QObject
但如果我这样做了,我得到了这个:
'class MyCircle' has no member named 'geometry'/'setgeometry'
如果我必须自己定义几何属性,继承QObject的目的是什么?
希望你能帮助我,如果我的问题含糊不清,我很抱歉,这是我的第一个问题,所以我真的不知道你的期望。
非常感谢您花时间回答。
【问题讨论】:
标签: c++ qt inheritance qt5 qproperty