QPropertyAnimation动画的控件看不到以及构造函数的属性如何来

下面的代码是QPropertyAnimation中的实例代码:

QPropertyAnimation *animation = newQPropertyAnimation(myWidget, "geometry");

animation->setDuration(10000);

animation->setStartValue(QRect(0, 0, 100,30));

animation->setEndValue(QRect(250, 250,100, 30));

animation->start();

参考这段代码,自己利用QLabel产生动画,代码如下,但是QLabel没有显示

QLabel *pL = new QLabel(this);

pL->setFixedSize(50, 50);

pL->setAutoFillBackground(true);

pL->setBackgroundRole(QPalette::Dark);

QPropertyAnimation *animation = newQPropertyAnimation(pL, "geometry");

animation->setDuration(10000);

animation->setStartValue(QRect(0,0, 50,50));

animation->setEndValue(QRect(300, 300,50, 50));

animation->start();

查看了网上的例子(链接http://jingyan.baidu.com/article/154b46315757b628ca8f4116.html),那是因为相关的控件还没有show,因此,修改的代码如下,即可显示

QLabel *pL = new QLabel(this);

    pL->setFixedSize(50, 50);

    pL->setAutoFillBackground(true);

    pL->setBackgroundRole(QPalette::Dark);

    pL->show();

    QPropertyAnimation *animation = newQPropertyAnimation(pL, "geometry");

    animation->setDuration(10000);

    animation->setStartValue(QRect(0,0, 50,50));

    animation->setEndValue(QRect(300, 300,50, 50));

    animation->start();

还有一个问题,QPropertyAnimation构造函数中的”geometry”到底是怎么来的,琢磨了很久,应该是这样来的,在参考文档中,找到QWidget这一个类,然后找到setGeometry这个属性,然后文档会跳转到


所以,我猜想”geometry”应该就是对应一个类的Property,如下图


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值