Trying to control individual QMenu titles color
-
Yes, you can do it using
Qt style sheets
.Example code:
QMenu { background-color: #ABABAB; /* sets background of the menu */ border: 1px solid black; } QMenu::item { /* sets background of menu item. set this to something non-transparent if you want menu color and menu item color to be different */ background-color: transparent; } QMenu::item:selected { /* when user selects item using mouse or keyboard */ color: #FF0000; // for red color background-color: #654321; }
More details here - Qt Style Sheets Examples
Also you can set your style sheet for specific menu item using
setObjectName("myMenuItem")
function.Usage:
QMenu::item#myMenuItem { color: #FF0000; // for red color }
-
Try to
setObjectName("myMenuItem")
function to appropriate view and style:QMenu::item#myMenuItem { color: #FF0000; // for red color }
or try this for top level menu:
QMenu#myMenuItem { color: #FF0000; // for red color }
If you can't solve your problem then post some code so I can help you.
-
@Cobra91151 , thanks for your help!
I have a top level menu bar called m_menuBar.
That menu has (among others) a QMenu called menuView, with the title "View".
menuView has 3 actions.when I do this in code:
menuView->setObjectName("ColorThis");
m_menuBar->setStyleSheet("QMenu::item#ColorThis {color: #FF0000;}");The three actions under menuView get painted in red, but the title "View" stays regular (black).
-