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. QMenu stylesheet
Qt 6.11 is out! See what's new in the release blog

QMenu stylesheet

Scheduled Pinned Locked Moved Unsolved General and Desktop
14 Posts 4 Posters 6.5k Views 3 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.
  • S SourceCreator

    Hello!

    I am creating a QT application and I just created a QMenuBar.
    I am trying to style a QMenu but the code does not accept it.

    NOTE: I am writing the program with VSCode and not with QT Creator.

    QT Code:
        // ========== Menu Item's Configuration ==========
        this -> start -> setTitle("Start");
        this -> help -> setTitle("Help");
        
    
        // ========== Menu's Configuration ==========
        this -> menu -> setStyleSheet("QMenuBar { \
                                        background-color: #FFFFFF; \
                                     }");
        this -> menu -> addMenu(this -> start);
        this -> menu -> addMenu(this -> help);
    

    Thanks BTW!

    JonBJ Offline
    JonBJ Offline
    JonB
    wrote on last edited by
    #3

    @SourceCreator said in QMenu stylesheet:

    I am trying to style a QMenu but the code does not accept it.

    Hello and welcome. Does this mean you get some error when you try to compile it, or something else?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SourceCreator
      wrote on last edited by SourceCreator
      #4

      @JonB
      No. The problem is that the Menu does not take my style. The mingw does not pick up any problems for me. But when executing the program the menu does not show a custom style

      SGaistS 1 Reply Last reply
      0
      • S SourceCreator

        @JonB
        No. The problem is that the Menu does not take my style. The mingw does not pick up any problems for me. But when executing the program the menu does not show a custom style

        SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #5

        @SourceCreator because you wrote a stylesheet for a QMenuBar and not a QMenu.

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

        S 1 Reply Last reply
        1
        • SGaistS SGaist

          @SourceCreator because you wrote a stylesheet for a QMenuBar and not a QMenu.

          S Offline
          S Offline
          SourceCreator
          wrote on last edited by
          #6

          @SGaist
          Proof.PNG
          Okey... I have my styles.qss created and I added this.
          My QMenu stills same.

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

            How are you using now ?

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

            S 1 Reply Last reply
            0
            • SGaistS SGaist

              How are you using now ?

              S Offline
              S Offline
              SourceCreator
              wrote on last edited by
              #8

              @SGaist
              Proof.PNG
              I'm using a .qss file
              All styles of widgets are working but the one that is not, is the QMenu's one
              In this picture, QMenuBar's one is working

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

                What I meant is how are you loading it ?

                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
                • S SourceCreator

                  @SGaist
                  Proof.PNG
                  I'm using a .qss file
                  All styles of widgets are working but the one that is not, is the QMenu's one
                  In this picture, QMenuBar's one is working

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by JonB
                  #10

                  @SourceCreator Which platform are you on? [EDIT: I see you said "VSCode" => Windows]

                  @SGaist Is menu background color something which requires Fusion style?
                  [Found reference: [Solved ] Background color of QMenu by StyleSheet doen't work this]

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    mchinand
                    wrote on last edited by
                    #11

                    There's also QMenu::item subcontrols: https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qmenu

                    S 1 Reply Last reply
                    0
                    • M mchinand

                      There's also QMenu::item subcontrols: https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qmenu

                      S Offline
                      S Offline
                      SourceCreator
                      wrote on last edited by SourceCreator
                      #12

                      @mchinand Is not working for me
                      @SGaist I'm loading with a QFile one
                      @JonB Yes it changes, but QMenu stills same :(

                      JonBJ 2 Replies Last reply
                      0
                      • S SourceCreator

                        @mchinand Is not working for me
                        @SGaist I'm loading with a QFile one
                        @JonB Yes it changes, but QMenu stills same :(

                        JonBJ Offline
                        JonBJ Offline
                        JonB
                        wrote on last edited by JonB
                        #13

                        @SourceCreator
                        Try

                        qApp->setStyle(QStyleFactory::create("fusion"));
                        //or
                        QApplication::setStyle(QStyleFactory::create("Fusion"));
                        

                        early in your program. Does that change behaviour?

                        1 Reply Last reply
                        0
                        • S SourceCreator

                          @mchinand Is not working for me
                          @SGaist I'm loading with a QFile one
                          @JonB Yes it changes, but QMenu stills same :(

                          JonBJ Offline
                          JonBJ Offline
                          JonB
                          wrote on last edited by
                          #14

                          @SourceCreator
                          I don't know what it looks like for you. From the docs example put in the

                          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;
                          }
                          

                          Does that make it look like it's supposed to?

                          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