daj
daj

Reputation: 7183

Qt: QAction doesn't appear in menu if the constructor string starts with the substring "about"

Are certain strings treated differently by the QAction constructor? This is very strange - if the QString in the constructor begins with "About" that seems to make the QAction invisible in the menu.

This snipped is within a method of a child class of QMainWindow:

mFileMenu = new QMenu(tr("&File"), mMenuBar);
mFileMenu->addAction(new QAction(tr("Export &Data"), mFileMenu)); // appears
mFileMenu->addAction(new QAction(tr("About"), mFileMenu)); // doesn't appear
mFileMenu->addAction(new QAction(tr("Abouut"), mFileMenu)); // appears
mFileMenu->addAction(new QAction(tr("Abouto"), mFileMenu)); // doesn't appear
mFileMenu->addAction(new QAction(tr("_About"), mFileMenu)); // appears
menuBar()->addMenu(mFileMenu);

Can someone explain this behavior?

Upvotes: 0

Views: 425

Answers (1)

Antonio Dias
Antonio Dias

Reputation: 2881

If you are on Mac there is a note on the docs:

Qt for Mac OS X also provides a menu bar merging feature to make QMenuBar conform more closely to accepted Mac OS X menu bar layout.

The merging functionality is based on string matching the title of a QMenu entry. These strings are translated (using QObject::tr()) in the "QMenuBar" context.

If an entry is moved its slots will still fire as if it was in the original place.

The table below outlines the strings looked for and where the entry is placed if matched:

note

So the action does not disappeared anyway, this was placed on the application menu as a you can see in the following example:

enter image description here

Upvotes: 0

Related Questions