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 ] Background color of QMenu by StyleSheet doen't work this

[Solved ] Background color of QMenu by StyleSheet doen't work this

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 9.5k 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.
  • C Offline
    C Offline
    curator
    wrote on last edited by
    #1

    Hi, I tried to work with Stylesheet and added in the constructor of my QMainWindow a line
    @
    this->setStyleSheet(" * {background-color: blue;color: yellow;} QPushButton {background-color: red;} QMenu::item::selected {background-color: black;}");
    @

    Basically, it works for all items, but not for the Menubar, which I create by
    @
    m_FileNew = new QAction("new database",this);
    ...
    m_FileMenu = new QMenu("File", this);
    menuBar()->addMenu(m_FileMenu);

    m_FileMenu->addAction(m_FileNew);
    m_FileMenu->addAction(m_FileOpen);
    ...
    @

    However, get GUI, all widgets are colored, even the entries in the menu "new database" etc., but not the "File" entry, where the background color is still gray (as default)

    I tried to google around, but didnt find a solutation yet. Does anyone have an idea, what i got wrong or if there is a workaround.

    kind regards,
    curator

    1 Reply Last reply
    0
    • P Offline
      P Offline
      Peppy
      wrote on last edited by
      #2

      Try to set stylesheets for QMenuBar...

      QMenu is a global scope for any kind of a menu, e.g. Context Menu.

      1 Reply Last reply
      0
      • C Offline
        C Offline
        curator
        wrote on last edited by
        #3

        Hi, thank you for your post.

        Unfortunately, the Menu is neither yellow nor black. So I would expect, that it is already covered by "* {background-color: "

        Am I correct?

        1 Reply Last reply
        0
        • P Offline
          P Offline
          Peppy
          wrote on last edited by
          #4

          Yea, it is covered by that, but everything (from Window's background to buttons) will have that background color. And also try to define stylesheets for
          @QMenuBar::item {}@

          1 Reply Last reply
          0
          • C Offline
            C Offline
            curator
            wrote on last edited by
            #5

            It should be covered, but as I mentioned, ir remains at the original color.

            Maybe it is a different problem:

            Ich tried this example:
            http://codeprogress.com/cpp/libraries/qt/QMenuBarSetMenuBackGround.php#.UTyXnFczSYQ

            But, the Menu1 has NO red background an my PC. They mention problems with qtconfig, but I have no odea, what this means

            regards,
            curator

            1 Reply Last reply
            0
            • C Offline
              C Offline
              curator
              wrote on last edited by
              #6

              Hi, finally, i made it.

              I had to add the line:
              @app.setStyle(QStyleFactory::create("fusion"));@

              Now it works!

              regards,
              curator

              1 Reply Last reply
              0
              • D Offline
                D Offline
                dreamerindia
                wrote on last edited by
                #7

                thanks. it helped me too.

                add [Solved] in the title.

                ~Ravivarman~

                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