首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >QPropertyAnimation不工作

QPropertyAnimation不工作
EN

Stack Overflow用户
提问于 2017-01-22 07:33:13
回答 1查看 661关注 0票数 1

我正在尝试使用Qt的动画框架。我正在使用Qt网站上的一些示例代码,但它不起作用,错误:setGeometryDp: Unable to set geometry 100x30+0+0 on QWidgetWindow/'QPushButtonClassWindow'. Resulting geometry: 120x30+0+0 (frame: 8, 31, 8, 8, custom margin: 0, 0, 0, 0, minimum size: 0x0, maximum size: 16777215x16777215).

代码语言:javascript
复制
QPushButton button("Animated Button");
button.setGeometry(0, 0, 100, 30);
button.show();

QPropertyAnimation animation(&button, "geometry");
animation.setDuration(10000);
animation.setStartValue(QRect(0, 0, 100, 30));
animation.setEndValue(QRect(250, 250, 100, 30));

animation.start(); 

我不知道我做错了什么。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-01-22 07:58:08

对象超出作用域

这是可行的:

代码语言:javascript
复制
QPushButton *button = new QPushButton();
button->setGeometry(0, 0, 100, 30);
button->show();

QPropertyAnimation *animation = new QPropertyAnimation(button, "geometry");
animation->setDuration(10000);
animation->setStartValue(QRect(0, 0, 100, 30));
animation->setEndValue(QRect(250, 250, 100, 30));

animation->start();

编辑:我的最终解决方案

代码语言:javascript
复制
QPushButton *button = new QPushButton(this);
button->setGeometry(0, 0, 100, 30);
button->show();

QPropertyAnimation *animation = new QPropertyAnimation(button, "geometry");
animation->setDuration(10000);
animation->setStartValue(QRect(0, 0, 100, 30));
animation->setEndValue(QRect(250, 250, 100, 30));

connect(animation, SIGNAL(finished()), animation, SLOT(deleteLater()));

animation->start();
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41785728

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档