QMacTouchBar has landed KDAB contributes the widget in QtMacExtras
QMacTouchBar has landed
Recent Apple MacBook Pro models contain an entirely new hardware feature, the touchbar. The touchbar is a touch-sensitive OLED strip sitting above the standard keyboard, where the function keys used to be. macOS uses it for some of the physical buttons that used to be located there, such as volume controls, but it is also possible to use the touchbar yourself, both as a graphical output device, and to trigger various activities.
Not a lot of packaged software makes use of it yet, but of course Apple’s own applications as well as recent versions of Microsoft Office and various Adobe packages use this to the fullest.
Support for Qt Developers
Qt developers were left out up until now, since there was no support in Qt for this. This has now changed, however, since KDAB just contributed QMacTouchBar, a widget in the QtMacExtras module that was written by KDABian Christoph Schleifenbaum, and that is already being used in some of KDAB’s own internal tools.
This is a welcome addition since Apple is not making interfacing with its system components from C++ particularly easy. This requires code written in Objective-C, one of Apple’s favorite programming languages, to interface with the built-in Cocoa libraries, as well as the necessary glue code written in C++ to make the touchbar appear as a perfectly ordinary Qt widget to Qt applications.
Currently supported are QTabBar, QMessageBox, QDialogButtonBox (Apple is using the touchbar a lot to show the buttons that close a dialog, such as “OK” and “Cancel”), and QWidgetAction, and it is possible to mark a QAction as the principal action as well as the escape action. Action icons are already supported, and further additions are planned.
Until QMacTouchBar has been merged upstream, you can find it here.
Is there any way to do custom painting on the touchbar, or get touch events?
Hello, yes, and it’s quite easy. You can use QWidgetAction and thus any widget that you can paint on. Touch events come to the widget delivered as mousePress/mouseMove/mouseRelease events, however, only the x coordinate will be valid, the y coordinate will always be the center of the touchbar.
The Patch status now says Abandoned.
Sadly, The Qt Company staff did not feel this was a valuable addition to Qt and refused to merge it. We have now made the code available at https://github.com/KDAB/KDMacTouchBar.
Thanks for this, I was waiting for it from Qt. It is still very usefull, there are so many MacBooks with Touchbar out there.