Multiple stylesheets for qt application -
is possible have multiple stylesheets single qt application , select of them needed?
for instance, have different styles of push buttons within application. understand have like:
qpushbutton { background-color: green; }
and push buttons have green style per above line. however, have stylesheet somehow this:
qpushbutton1 { background-color: blue; } qpushbutton2 { background-color: green; }
i may need place several push buttons in application , each of those, want select either qpushbutton1 style or qpushbutton2 style.
is feasible within 1 or multiple stylesheets, can use setstylesheet() enable custom style?
thanks!
you can use global stylesheet , set special settings each special object name.
#qpushbutton1 { background-color: blue; } #qpushbutton2 { background-color: green; }
but in case need set these object names in code. can done with:
ui->pushbutton1->setobjectname("qpushbutton1"); ui->pushbutton2->setobjectname("qpushbutton2");
it possible set same object name different widgets.
about changing objectname
. when change objectname
, qt
not re-apply stylesheet
automatically (it done better performance), should manually. can use objectnamechanged
signal , re-apply stylesheet
in corresponding slot or like:
ui->pushbutton_2->setobjectname("qpushbutton1"); qapp->setstylesheet(qapp->stylesheet());//re-apply