我正在尝试使用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).
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();
我不知道我在做什么错。
最佳答案
对象超出范围
这有效:
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();
编辑:
我的最终解决方案
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();
关于c++ - QPropertyAnimation不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41785728/