Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] MenuBar Color
Forum Updated to NodeBB v4.3 + New Features

[Solved] MenuBar Color

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 7.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    DBoosalis
    wrote on last edited by
    #1

    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

    Thanks
    David

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • D Offline
        D Offline
        DBoosalis
        wrote on last edited by
        #3

        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()) + ";";
        mainMenuBar->setStyleSheet(colorStr);

        fileMenu->setStyleSheet(menuStyle);
        optionMenu->setStyleSheet(menuStyle);
        schemaMenu->setStyleSheet(menuStyle);
        helpMenu->setStyleSheet(menuStyle);@

        1 Reply Last reply
        1
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          What about styling QMenuBar and QMenu in one stylesheet ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • D Offline
            D Offline
            DBoosalis
            wrote on last edited by
            #5

            Brilliant !!!

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved