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
QtWS25 Last Chance

QMenu stylesheet

Scheduled Pinned Locked Moved Unsolved General and Desktop
14 Posts 4 Posters 4.0k Views
  • 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 Offline
    S Offline
    SourceCreator
    wrote on 28 Oct 2021, 18:21 last edited by
    #1

    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!

    J 1 Reply Last reply 28 Oct 2021, 18:36
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 28 Oct 2021, 18:31 last edited by SGaist
      #2

      Hi and welcome to devnet,

      Is menu a QMenu ? If so the style sheet won't be applied to the QMenuBar it belongs to as it's a child of the QMenuBar.

      See the QMenu stylesheet example here.

      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
      1
      • S SourceCreator
        28 Oct 2021, 18:21

        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!

        J Offline
        J Offline
        JonB
        wrote on 28 Oct 2021, 18:36 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 28 Oct 2021, 18:36 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

          S 1 Reply Last reply 28 Oct 2021, 18:41
          0
          • S SourceCreator
            28 Oct 2021, 18:36

            @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

            S Offline
            S Offline
            SGaist
            Lifetime Qt Champion
            wrote on 28 Oct 2021, 18:41 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 28 Oct 2021, 18:50
            1
            • S SGaist
              28 Oct 2021, 18:41

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

              S Offline
              S Offline
              SourceCreator
              wrote on 28 Oct 2021, 18:50 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
              • S Offline
                S Offline
                SGaist
                Lifetime Qt Champion
                wrote on 28 Oct 2021, 18:58 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 28 Oct 2021, 19:00
                0
                • S SGaist
                  28 Oct 2021, 18:58

                  How are you using now ?

                  S Offline
                  S Offline
                  SourceCreator
                  wrote on 28 Oct 2021, 19:00 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

                  J 1 Reply Last reply 28 Oct 2021, 19:06
                  0
                  • S Offline
                    S Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on 28 Oct 2021, 19:06 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
                      28 Oct 2021, 19:00

                      @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

                      J Offline
                      J Offline
                      JonB
                      wrote on 28 Oct 2021, 19:06 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 28 Oct 2021, 19:09 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 28 Oct 2021, 19:13
                        0
                        • M mchinand
                          28 Oct 2021, 19:09

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

                          S Offline
                          S Offline
                          SourceCreator
                          wrote on 28 Oct 2021, 19:13 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 :(

                          J 2 Replies Last reply 28 Oct 2021, 19:16
                          0
                          • S SourceCreator
                            28 Oct 2021, 19:13

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

                            J Offline
                            J Offline
                            JonB
                            wrote on 28 Oct 2021, 19:16 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
                              28 Oct 2021, 19:13

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

                              J Offline
                              J Offline
                              JonB
                              wrote on 28 Oct 2021, 19:24 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

                              7/14

                              28 Oct 2021, 18:58

                              • Login

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