Back to Blog home

Mac Toolbars for Qt Quick

Published on Friday April 08, 2011 by admin in Qt Quick macOS | Comments

As Jens wrote a while ago, we are looking into customizing Qt Quick for use on the desktop. In one of the comments he also revealed that I'm working a Mac-specific project. Time to blog!

Toolbar in action : Nothing we haven't seen on Mac before, although the customize menu is new to Qt applications.

What is different from the current Qt solution? First of all, we're using NSToolBar instead of QToolBar, which means we get the correct native look and feel (including the desired customization menu) for free. Second, the toolbar can be created just like any other QML item:

MacToolBar {
MacToolButton {
text : "Button 1"
iconSource : "images/qtlogo.png"
toolTip : "This is button number 1"
onActivated : status.text = "Button1 Clicked"
}

MacToolButton { standardItem : MacToolButton.ShowColors }
MacToolButton { standardItem : MacToolButton.Space }
}

MacToolBars are not drawn on the QML scene, but instead attach a NSToolBar to the window.

The color panel can be accessed in a similar fashon:

MacColorPanel {
onColorChanged : { status.color = color; }
}

Finally, if you are using Qt from C++ there is also a QAction-based interface:

QWidget *window = ...;
QtMacToolBar * macToolBar = new QtMacToolBar(window);
QAction * fooAction = macToolBar->addAction("FooButton");
QAction * barAction = macToolBar->addAction("BarButton");
macToolBar->showInWindow(window);

Code is at examples/MacToolbar.qml from qt-components/desktop, branch "mac".

Edit:
Removed ampersand from C++ example.

Subscribe to Our Blog

Stay up to date with the latest marketing, sales and service tips and news.

We are updating our comment system and you could face some issues. Please write to us at feedback@qt.io to report issues/bugs.