c++ - [Qt]How to support :pressed state of style sheet for custom widget? -
what have :-
i have custom widget extends qframe (instead of qwidget qframe has working paintevent implementation). have overridden mousepressed() , mousereleased() emit pressed() released() , clicked() signals. upto point woring fine expected.
what need :-
this custom widget having basic style sheet support , supports :hover state fine. :pressed state not working. have figured out bcoz not supported qframe/qlabel etc. wish know need in order support :pressed state. should set attribute / property on pressed , released or else ?
you can set property qlabel
(or whatever widget using) , change value of property. use property in stylesheets.
example:
this->setstylesheet("*[myproperty=\"true\"] { background-color: red }"); d_label = new qlabel("dynamic label", this); d_label->setproperty("myproperty", false);
then in mousepressevent set , in mousereleaseevent unset property:
d_label->setproperty("myproperty", true); // or false when wish unset style()->unpolish(d_label); style()->polish(d_label); // force stylesheet recomputation
Comments
Post a Comment