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. Simple question about Qt menus under OSX
Forum Updated to NodeBB v4.3 + New Features

Simple question about Qt menus under OSX

Scheduled Pinned Locked Moved General and Desktop
9 Posts 3 Posters 2.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.
  • M Offline
    M Offline
    miketopen
    wrote on last edited by
    #1

    This question is properly easy for most of you. However, I did not find an appropriate answer on the question in the Qt documentation. When Qt is building an application on OSX it is imitating the behaviour of the native OSX menu structure by creating a menu entry with the program name. How can I add menu actions under this automatically generated entry. For example if I want to put an "About"-dialog there.

    Thanks for your help

    Mike
    

    www.topen.org

    1 Reply Last reply
    0
    • B Offline
      B Offline
      butterface
      wrote on last edited by
      #2

      You should have something like

      @
      QMenu *menu = QMenu("ProgramName");
      @

      and there you can add actions using

      @
      menu->addAction("About", ...);
      @

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

        Hi,

        There are several possibilities. For the "standard" entries like Preferences and About, you can just use actions with the right names (don't forget to translate them)

        Otherwise you can use "QAction's menu role":http://qt-project.org/doc/qt-4.8/qaction.html#MenuRole-enum if you want to add several entries i.e. under Preferences

        Hope it helps

        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
        • M Offline
          M Offline
          miketopen
          wrote on last edited by
          #4

          Thanks both of your for your replies. However, I still didn't manage it.

          The first answer from butterface was promising. Just taking the program name to get the pointer to the menu entry. Like that:

          @QMenu *menu = QMenu("ProgramName");@

          Problem is: QMenu("ProgramName") is not returning a pointer, and my attempts to create one from it failed, as well as just using the object.

          The second hint from SGaist gave me a search direction. And the idea of giving the action a specific rule is good. But I still don't know where to add the action afterwards just setting the menu role was not enough.

          Bests

          Mike

          www.topen.org

          1 Reply Last reply
          0
          • B Offline
            B Offline
            butterface
            wrote on last edited by
            #5

            Sorry, my bad. This should be

            @
            QMenu *menu = new QMenu("ProgramName");
            @

            Btw.: You will not get the menu entry generated by OSX. It is to create your own one. If you don't want that I misunderstood your post.

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

              You don't need the menu "ProgramName", this one is done for you.

              You can use About and Preferences... These two should be automatically put in the right place. The menu role is to be used if you want to add custom entries.

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

                Hi,

                I had again some time to try your suggestions.

                1. With the method of creating a new Menu("Programname") I get a new pointer on a new dropdown menu, but I have to put it somewhere, right? So I put it in the menubar(). With the result, that I got a second menu with the programname. Which is fine, but it is not what I search.

                2. With the second approach using just the action with the name "About", I also do not now where to put the pointer of the action, if I want it under the program name entry. If i just add it (with addAction) to the menubar() I do not see any item. However, maybe it helps when I show how I generate the actions:

                @ // Add Aboutdialog Action
                _actionAbout = new QAction(tr("About"),this);
                _actionAbout->setStatusTip(tr("About TLab"));
                connect(_actionAbout,SIGNAL(triggered()),this,SLOT(about()));
                @

                I think is quite straight forward.....It just got into my mind, I am using Qt 5.1, maybe that is a problem that the behaviour is different......

                What do you think?

                Bests

                Mike

                www.topen.org

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

                  There you have a basic setup which should be cross platform

                  @
                  QAction *aboutAction = new QAction(tr("&About..."), this);
                  aboutAction->setStatusTip(tr("Show About dialog"));

                  QAction *preferencesAction = new QAction(tr("&Preferences..."), this);
                  preferencesAction->setShortcut(tr("Ctrl+,"));
                  preferencesAction->setStatusTip(tr("Show preferences dialog"));

                  QMenu *helpMenu = menuBar()->addMenu(tr("&Help"));
                  helpMenu->addAction(aboutAction);
                  QMenu *toolMenu = menuBar()->addMenu(tr("&Tools"));
                  toolMenu->addAction(preferencesAction);
                  @

                  The actions should be moved at the right places.

                  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
                  • M Offline
                    M Offline
                    miketopen
                    wrote on last edited by
                    #9

                    Hi,

                    I tested the menu generation on Qt 4.8 and it is working as expected. Guess I found a bug. Which I also already "posted":https://bugreports.qt-project.org/browse/QTBUG-33226

                    Thanks for your help

                     Mike
                    

                    www.topen.org

                    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