2011/03/10

Making QT behave properly on Mac.

Couple of things I found out that helped porting a QT application to Mac:

The QMainWindow you create does not look like a native Cocoa window. The status bar is there, no matter what you request, the menu doesn't port and the icon is yucky.
Here's what you can do:

Remove status bar/resize grip:
void setupWindowWithoutStatusBar(QWidget* w){
NSView* view = (NSView*) w->winId();
NSWindow* win = [view window ];
[win setShowsResizeIndicator:FALSE];
NSUInteger mask = [win styleMask];
[win setStyleMask:mask | ~NSResizableWindowMask];
}


Don't show unneeded icon in the title bar and move a QAction to Mac's main menu:

#ifndef Q_OS_MAC
setWindowIcon( QIcon(":/windowIcon") );
#else
myAction->setMenuRole(QAction::ApplicationSpecificRole);
#endif