Mac desktop integration and qt_mac_set_menubar_merge( bool )



  • Hi all,

    I am currently in the process of "porting" a C++ application to Qt5 and all its amazing amazements. It is a windowless app, with only a QSystemTrayIcon giving information about a simple background process. When built against Qt 4.8.4 the "Quit", "Settings" and "About" menus are shown in the context menu associated with the tray icon. However, when built against Qt 5.0.0, the same menus items simply disappear.
    I found that odd but remembered that Qt does some work for you to follow Mac OS X user interface guidelines when it comes to those menu items. As I don't have any windows, I chose not to have a dock icon, and by extension no menu bar. This makes those quite useful menu items simply inaccessible to the user. Bummer...

    So I looked up the documentation for the method: @qt_mac_set_menubar_merge( bool )@
    Although this method is clearly documented, it is nowhere to be found in Qt 5.0.0 (it is available in 4.8.4).

    I know this symbol is not publicly defined in the Qt headers by default so I defined it myself. With Qt 4.8.4 at link time the symbol is found and I can build the application. The problem with Qt 5.0.0 is that this very same symbol can't be found at link time.
    I scanned the latest Qt 5.0.1 source code for it and found that it can only be found in an example "languagechooser.cpp" source code surrounded by the @#ifdef Q_WS_MAC@
    guard which has been deprecated in Qt 5, and in the documentation generation files. Second bummer...

    My understanding is that this method is no longer part of the Qt API as of 5.0.0, however I am stuck with no solution when it comes to solving that issue. Did similar options move to other parts of the API ? If yes where ?

    Thanks in advance to anybody who can help me with this.


  • Lifetime Qt Champion

    Hi,

    IIRC the lib is qtmacextras (there is also one for windows and X11). The platform very specific stuff have been move the *extras libraries (you should find them on gitorious)

    Hope it helps



  • Well I found a solution to my problem:
    @QMenu* menu = new QMenu();

    // Settings
    QAction* action;
    action = menu->addAction( tr( "Settings" ), this, SLOT( settings() ) );
    action->setMenuRole( QAction::NoRole );

    // About
    action = menu->addAction( tr( "About" ), this, SLOT( about() ) );
    action->setMenuRole( QAction::NoRole );

    // Quit
    action = menu->addAction( tr( "Quit" ), qApp, SLOT( quit() ) );
    action->setMenuRole( QAction::NoRole );@

    The @setMenuRole( QAction::NoRole )@ did the trick!



  • qt_mac_set_menubar_merge() seems not to be a part of QtMacExtras:

    @$ cd qtmacextras
    $ fgrep qt_mac_set_menubar_merge * -R

    no output@



  • ... and the
    @setMenuRole( QAction::NoRole )@

    trick doesn't do the job in my environment (Qt 5.1.0)



  • Ok, the correct answer is now to set specifically the menuRole rather than QAction::NoRole. For example:

    @// About
    action = menu->addAction( tr( "About" ), this, SLOT( about() ) );
    action->setMenuRole( QAction::Preferences );@


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.