Important: Please read the Qt Code of Conduct -

Trying to control individual QMenu titles color

  • I wonder if I can do this programmatically (change the color of a menu title):
    This should explain what I want:

  • @hashtagqt

    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.


    QMenu::item#myMenuItem {
         color: #FF0000; // for red color

  • That does change the color of all the children of the "View" menu. I just want to change the color of the "View" label itself, within the top level menu bar.

  • @hashtagqt

    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:
    m_menuBar->setStyleSheet("QMenu::item#ColorThis {color: #FF0000;}");

    The three actions under menuView get painted in red, but the title "View" stays regular (black).

  • @hashtagqt

    Ok. Try to set style sheet like this:

    menuView->setStyleSheet("color: #FF0000;");

  • Same exact outcome.

Log in to reply