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 addSection Not Showing
Forum Updated to NodeBB v4.3 + New Features

QMenu addSection Not Showing

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 5 Posters 3.4k 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.
  • webzoidW Offline
    webzoidW Offline
    webzoid
    wrote on last edited by
    #1

    Is there any reason why the addSection function of a QMenu would have no effect?

    For example, the following code:

    QMenu menu;
    menu.addSection("Connected");
    menu.addAction("None");
    menu.addSeparator();
    menu.addSection("Available");
    menu.addAction("None");
    menu.addSeparator();
    menu.addAction("Quit");
    

    Results in a menu with just the actions and separators visible.

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

      Hi,

      From the documentation from addSection:

      The rendering of the hint is style and platform dependent. Widget styles can use the 
      text information in the rendering for sections, or can choose to ignore it and render 
      sections like simple separators.
      

      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
      2
      • webzoidW Offline
        webzoidW Offline
        webzoid
        wrote on last edited by
        #3

        @SGaist thanks for the clarification - so I can presume then, that Windows does not render these sections. Thanks again.

        1 Reply Last reply
        0
        • R Offline
          R Offline
          rmam
          wrote on last edited by
          #4

          I've experienced this very same problem and although I'm very late to the discussion I have to say that it's possible to render separators and separator labels in Windows. The trick is to use a widget style that supports these features.

          One such widget theme is the "fusion" style shown in Qt's wiget gallery. For a quick test, just run the Qt application with the fusion style by passing the "-style fusion" command line argument.

          1 Reply Last reply
          0
          • 3 Offline
            3 Offline
            3nids
            wrote on last edited by
            #5

            under macos, there is also no text.
            I would have expected this method to create a disabled entry in the menu, it would be more helpful and consistent across the different styles.

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

              @3nids By default Qt OS specific styles follow their respective OS guidelines. These OSs have all their specific guidelines which may or may not have things in common with the others.

              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
              • T Offline
                T Offline
                TC__
                wrote on last edited by TC__
                #7

                Here is a workaround if you only have your first section that is not showing :
                Add a QWidgetAction before your first addSection
                Add an empty QWidget as default widget of the QWidgetAction
                And voilĂ , your first section is now displayed with nothing visible above it.

                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