Qt: 为什么我的animation没有效果。

丨秋水丨 2017-06-07 10:35:48

#include"MyButton.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MyButton button;
button.setText("button");
button.show();

QPropertyAnimation animation(&button, "_styleSheet");
animation.setDuration(10000);
animation.setStartValue(QString("background:yellow"));
animation.setEndValue(QString("background:red"));
animation.start();
return a.exec();
}


MyButton.h:
class MyButton :public QPushButton
{
Q_OBJECT
Q_PROPERTY(QString _styleSheet READ _styleSheet WRITE _setStyleSheet)
public:
MyButton(QWidget*parent = 0);
QString _styleSheet();
void _setStyleSheet(const QString&);
};

MyButton.cpp:
#include"MyButton.h"
MyButton::MyButton(QWidget*parent)
:QPushButton(parent)
{
}

void MyButton::_setStyleSheet(const QString& sty)
{
setStyleSheet(sty);
}

QString MyButton::_styleSheet()
{
return styleSheet();
}



我想让按钮颜色渐变。
但是我的代码运行的时候没有这种效果,为什么?
...全文
417 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
丨秋水丨 2017-06-09
  • 打赏
  • 举报
回复
没有解决问题。。。
赵4老师 2017-06-08
  • 打赏
  • 举报
回复
判断每个函数调用的返回值。

24,854

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 工具平台和程序库
社区管理员
  • 工具平台和程序库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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