⚠️ Forum Maintenance: Feb 6th, 8am - 14pm (UTC+2)

[Solved] MenuBar Color

  • I would like to be able to set a QMenuBar's background color. It sounds easy enough to do - just get the pallete and set the QPalette::window color. This in fact works on KDE, but for some reason it does not work on Ubuntu nor does it work on Windows. Is this a bug ? Or is it that the window managers do not let this happen.

    It does work if I set the color with a style sheet for menubar. But the problem here is that this also sets the colors of the menus and I do not want this. That is only want the menubar colour to change.

    The reason for the multicolour menubars is that the user can have lots of toplevel main windows open with my application and I want them to quickly be able to find the one they want by colour association.

    Hope someone has a answer for me. By the way the behaviour describe above is with Qt 5.2 and Qt 5.3


  • Lifetime Qt Champion


    IIRC, the OS can freely ignore the palette, so the style sheet path is probably your best bet

  • Yes

    I ended up doing it with style sheets and to keep the menus the same color I do something like the follwing, its a bit awkward but it works

    @colorStr = QString("background-color:") + QString(color.name()) + ";";


  • Lifetime Qt Champion

    What about styling QMenuBar and QMenu in one stylesheet ?

  • Brilliant !!!

Log in to reply