Search code examples
macosqttoolbartitlebar

How to get the height of Mac unified title and toolbar in Qt/C++


I have a Qt 4.7.4 with C++ app that uses the unified title and toolbar on Mac: setUnifiedTitleAndToolBarOnMac(true); At some point while my app is running, I need to know programmatically what the height of the unified title and toolbar is.

How can I get its height?


Solution

  • At least with Qt 4.8.4 and Mountain Lion, this looks a bit buggy:

    With toolbar on, QMainWindow::frameGeometry() reports wrong y position but correct total window size. Its height() minus QMainWindow::geometry()'s height() is the height of title bar and unified toolbar together in my tests. To find out how tall the toolbar alone is, you could hide it and use the difference.

    The Qt people working on this seem to have a few problems and have discontinued QMainWindow::setUnifiedTitleAndToolBarOnMac():

    The unified toolbar implementation from Qt 4 has not and will not be ported to Qt 5. This means calling QMainWindow::setUnifiedTitleAndToolBarOnMac has no effect on Qt 5. A replacement API which wraps NSToolbar is available in QtMacExtras.