gpt4 book ai didi

c++ - QPropertyAnimation 不工作

转载 作者:太空宇宙 更新时间:2023-11-04 13:06:55 31 4
gpt4 key购买 nike

我正在尝试使用 Qt 的动画框架。我正在使用 Qt 网站上的一些示例代码,但它无法正常工作,错误:setGeometryDp: 无法在 QWidgetWindow/'QPushButtonClassWindow' 上设置几何图形 100x30+0+0。生成的几何图形:120x30+0+0(帧:8、31、8、8,自定义边距:0、0、0、0,最小尺寸:0x0,最大尺寸: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/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com