c++ - QMenu: Set text color for specific QAction -
i have qmenu
context menu looks this:
menu - information_a - information_b - information_c
now want entry information_b
painted in different color. how can archive this?
edit: found best solution in post: link in case simple as:
qmenu contextmenu(this); qstring menustyle( "qmenu::item{" "color: rgb(0, 0, 255);" "}" ); contextmenu.setstylesheet(menustyle);
for more options , possibilities take @ answer in link provided above.
previous solution:
can use qwidgetaction
instead of qaction
, , define qlabel
text , stylesheet want, , assign qwidgetaction
. keep in mind have tweak width , height of qlabel
, in order same qaction
does.
sample code:
// label qlabel *text = new qlabel(qstring("your text here"), this); text->setstylesheet("color: blue"); // init widget action qwidgetaction *widact= new qwidgetaction(this); widact->setdefaultwidget(text); contextmenu.addaction(widact);
Comments
Post a Comment