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

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -