为什么通过QPropertyAnimation的方法button1不能360度旋转?

蜗牛哦 2016-01-20 08:06:23
  QPushButton *button1 = new QPushButton(uhomeBackWidget);
button1->move(0,0);
button1->resize(30,30);
button1->show();


QLabel *label = new QLabel("xyz",uhomeBackWidget);

label->move(100,100);
label->resize(30,30);
label->show();


//为图形项的rotation属性创建动画
QPropertyAnimation *animation =new QPropertyAnimation(button1,"rotation");
animation->setDuration(6000);
//animation->setStartValue(QRect(0,0,30,30));
//animation->setEndValue(QRect(360,360,30,30));
animation->setStartValue(0);
animation->setEndValue(360);
animation->setLoopCount(-1);
animation->start(QAbstractAnimation::KeepWhenStopped);



为什么这样创建的button1按钮不能360度旋转,如果通过场景,视图,图形项的方法就可以360旋转,比如
    QGraphicsScene scene;
scene.setSceneRect(-200,-200,400,400);
MyItem *item = new MyItem;
scene.addItem(item);
QGraphicsView view;
view.setScene(&scene);
view.show();

//为图形项的rotation属性创建动画
QPropertyAnimation *animation =new QPropertyAnimation(item ,"rotation");
animation->setDuration(6000);
//animation->setStartValue(QRect(0,0,30,30));
//animation->setEndValue(QRect(360,360,30,30));
animation->setStartValue(0);
animation->setEndValue(360);
animation->setLoopCount(-1);
animation->start(QAbstractAnimation::KeepWhenStopped);
...全文
351 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
pslov 2016-01-21
  • 打赏
  • 举报
回复
引用 2 楼 sanmaoljh 的回复:
按钮可以平移的 QPropertyAnimation *animation =new QPropertyAnimation(button1,"geometry"); 但是我也找不到button的geometry,应该与button1的属性没有关系吧!
就像四楼说的,按钮的父类QWidget有Geometry属性
冷静忍耐 2016-01-21
  • 打赏
  • 举报
回复 1
你头文件里得有这个: Q_PROPERTY(int rotation READ rotation WRITE setRotation) 然后自己实现rotation()和setRotation(int angle)函数。 不然它不知道rotation是啥东西。 场景的item有旋转是因为他像我上面一样定义了。如果它的类里没有,它父类肯定有。
蜗牛哦 2016-01-21
  • 打赏
  • 举报
回复
按钮可以平移的 QPropertyAnimation *animation =new QPropertyAnimation(button1,"geometry"); 但是我也找不到button的geometry,应该与button1的属性没有关系吧!
pslov 2016-01-20
  • 打赏
  • 举报
回复 1
我找了下,按钮并没有rotation属性

16,239

社区成员

发帖
与我相关
我的任务
社区描述
Qt 是一个跨平台应用程序框架。通过使用 Qt,您可以一次性开发应用程序和用户界面,然后将其部署到多个桌面和嵌入式操作系统,而无需重复编写源代码。
社区管理员
  • Qt
  • 亭台六七座
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧