Mac Toolbars for Qt Quick
April 08, 2011 by admin | 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.
Blog Topics:
Comments
Subscribe to our newsletter
Subscribe Newsletter
Try Qt 6.5 Now!
Download the latest release here: www.qt.io/download.
Qt 6.5 is the latest Long-Term-Support release with all you need for C++ cross-platform app development.
Qt World Summit 2023: Berlin awaits!
We're Hiring
Check out all our open positions here and follow us on Instagram to see what it's like to be #QtPeople.