24,854
社区成员
发帖
与我相关
我的任务
分享
#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();
}