APush { qproperty-shadowLength : 1; border:0px;}APush:pressed { qproperty-shadowLength : 3; border:3px solid black;}
class MyButton : public QPushButton{ Q_OBJECTprivate: int m_test;public: MyButton(QWidget* Parent = 0) : QPushButton(Parent), m_test(0) {this->ensurePolished();} virtual ~MyButton(); Q_PROPERTY(int test READ getTest WRITE setTest); void setTest(int test){m_test = test}; int getTest() const {return m_test;};}; MyButton* my = new MyButton(this); qDebug() << my->getTest();//0 my->setStyleSheet("qproperty-test:5"); qDebug() << my->getTest();//5
Q_PROPERTY(int test READ getTest WRITE setTest NOTIFY changeTest)...signals: void changeTest();...void APush::setTest(int newValue){ if (m_Test != newValue) { m_Test = newValue; emit changeTest(); }}
APush:pressed {qproperty-shadowLength : 3;
class testButton : public QPushButton{ Q_OBJECT Q_PROPERTY (int testProp READ getTestProp WRITE setTestProp)public: explicit testButton (QWidget *parent = 0); int getTestProp () { return testProp; } void setTestProp (int pPropVal) { testProp = pPropVal; setText (QString ().setNum (testProp)); }protected: virtual void mousePressEvent (QMouseEvent * e) { QPushButton::mousePressEvent (e); this->style ()->polish (this); } virtual void mouseReleaseEvent (QMouseEvent * e) { QPushButton::mouseReleaseEvent (e); this->style ()->polish (this); }private: int testProp;};testButton::testButton(QWidget *parent) : QPushButton(parent){ this->setStyleSheet (QLatin1String ("testButton {qproperty-testProp:1; border:0px;} testButton[down='true'] {qproperty-testProp:3; border:3px solid black;}"));}
void MyPushButton::paintEvent(QPaintEvent *e){ style()->polish(this); QPushButton::paintEvent(e);}