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. Hiding Menu in MainWindow

Hiding Menu in MainWindow

Scheduled Pinned Locked Moved Unsolved General and Desktop
11 Posts 3 Posters 4.3k 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.
  • ModelTechM Offline
    ModelTechM Offline
    ModelTech
    wrote on last edited by
    #1

    I would like to hide one of my menu's in the main window in case it has no actions (this depends on whether certain plugins are loaded or not). Calling setVisible(false) on the QMenu does not hide it. So, what is the correct approach for this case?

    1 Reply Last reply
    0
    • RatzzR Offline
      RatzzR Offline
      Ratzz
      wrote on last edited by
      #2

      @ModelTech
      Can you show what you have tried?

      --Alles ist gut.

      1 Reply Last reply
      2
      • Chris KawaC Offline
        Chris KawaC Offline
        Chris Kawa
        Lifetime Qt Champion
        wrote on last edited by
        #3

        What kind of menu is it? A context menu? On a menu bar? On a toolbar's action? On a button?
        If it's a menu added to a menu bar you should hide the action returned from addMenu(), not the menu itself.

        1 Reply Last reply
        2
        • ModelTechM Offline
          ModelTechM Offline
          ModelTech
          wrote on last edited by
          #4

          It's the menu of the QMainWindow. This is how I created the QMenu with QMainWindow::menuBar()

          AnalysisMenu = menuBar()->addMenu(tr("Analysis"));
          

          Subsequently, I have some code that may or may not add QActions to this AnalysisMenu. For this I use QMenu::addAction. Finally, I have tried the following to hide the menu in case it does not have actions:

          AnalysisMenu->setEnabled(!AnalysisMenu->actions().isEmpty());
          
          1 Reply Last reply
          0
          • Chris KawaC Offline
            Chris KawaC Offline
            Chris Kawa
            Lifetime Qt Champion
            wrote on last edited by Chris Kawa
            #5

            setEnabled does not hide an action. It only disables it (grays out depending on the style) and turns off a shortcut if it was assigned. Use setVisible() instead.

            1 Reply Last reply
            2
            • ModelTechM Offline
              ModelTechM Offline
              ModelTech
              wrote on last edited by ModelTech
              #6

              Oeps, that's my current code... I actually did use setVisible as follows, but it does not give the desired effect:

              AnalysisMenu->setVisible(!AnalysisMenu->actions().isEmpty());
              
              1 Reply Last reply
              0
              • Chris KawaC Offline
                Chris KawaC Offline
                Chris Kawa
                Lifetime Qt Champion
                wrote on last edited by
                #7

                If it doesn't work it means you're either not calling this code or you call it in a wrong place. It should be called whenever you change the contents of the menu (add/remove actions).

                1 Reply Last reply
                0
                • ModelTechM Offline
                  ModelTechM Offline
                  ModelTech
                  wrote on last edited by
                  #8

                  Have now done so, but that does not help... I am using Qt 5.7.1 if that matters.

                  1 Reply Last reply
                  0
                  • Chris KawaC Offline
                    Chris KawaC Offline
                    Chris Kawa
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    You'll gonna have to show some code - how you set up the menu, the part where you modify it and where you call the line. setVisible(false) hides an action so the problem is somewhere in your code.

                    1 Reply Last reply
                    0
                    • ModelTechM Offline
                      ModelTechM Offline
                      ModelTech
                      wrote on last edited by
                      #10

                      I just found out that the problem is platform related. On MacOS, it works as I expect. So, will dive a bit deeper ;)

                      1 Reply Last reply
                      0
                      • ModelTechM Offline
                        ModelTechM Offline
                        ModelTech
                        wrote on last edited by
                        #11

                        Yep, it also works correctly on Windows. It just does not work correctly on Ubuntu. It seems related to a menu problem that I experienced before on Ubuntu only. So, I guess that I will have to wait for a bug fix...

                        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