ingo
ingo

Reputation: 856

Fill MenuBar on Mac

I try to add a MenuBar to my app, that I develop on macOS and I have a problem where I do not have any idea for:

Works:

     QAction *freeNameAct = new QAction(tr("&Settin"), this);
     freeNameAct->setStatusTip(tr("Create a new file"));

     QMenu *fileMenu = menuBar()->addMenu(tr("&File2"));
     fileMenu->addAction(freeNameAct);

But does not work:

     QAction *freeNameAct = new QAction(tr("&Setting"), this);
     freeNameAct->setStatusTip(tr("Create a new file"));

     QMenu *fileMenu = menuBar()->addMenu(tr("&File2"));
     fileMenu->addAction(freeNameAct);

Is the menubar limited in text length?

Upvotes: 1

Views: 74

Answers (1)

Former contributor
Former contributor

Reputation: 2576

No, the problem is not the length. You may do something like this:

 QAction *freeNameAct = new QAction(tr("&Setting"), this);
 freeNameAct->setStatusTip(tr("Create a new file"));
 freeNameAct->setMenuRole(QAction::NoRole);

Each QAction has a menuRole property which controls the special placement of application menu items; however by default the menuRole is TextHeuristicRole which mean the menu items will be auto-detected by their text. Source

In your case, giving the action a text "Setting", it is placed under the application menu, with the text "Preferences..." (which is the default placement and name in macOS) and it is removed from the menu File2.

Upvotes: 2

Related Questions