Skip to content

KDMacTouchBar A quick introduction

Back in February we wrote about our work to add ‘MacOs touch bar‘ support to Qt. Between then and now, support has been added in QtCreator:

QtCreator Touch bar

KDMacTouchBar in QtCreator

However, the changes have not been integrated upstream in Qt, which means there is still no easy way to add support to your own applications. KDAB is happy to provide this via KDMacTouchBar, available as both LGPL and commercial licence.

This provides touch bar support as a separate library, supporting both qmake and cmake as a build system. Support can be quickly added to any new or existing application using code similar to this example:


MainWindow::MainWindow()
{
    setWindowTitle("KDMacTouchBar Example");
    resize(400, 200);

    // attach a touchbar to this window
    KDMacTouchBar *touchBar = new KDMacTouchBar(this);

    QIcon qtIcon(QStringLiteral(":qtlogo.png"));

    // add item
    QAction *action = new QAction(qtIcon, tr("Qt with touchbar"));
    touchBar->addAction(action);
    connect(action, &QAction::triggered, this, &MainWindow::activated);

    // separator
    touchBar->addSeparator();
    touchBar->addSeparator()->setText(tr("More items:"));

    // and more items
    QAction *action1 = new QAction(tr("Item 1"));
    touchBar->addAction(action1);
    connect(action1, &QAction::triggered, this, &MainWindow::activated);

    QAction *action2 = new QAction(tr("Item 2"));
    touchBar->addAction(action2);
    connect(action2, &QAction::triggered, this, &MainWindow::activated);

    // make special escape button
    QAction *quit = new QAction(tr("Quit"));
    touchBar->setEscapeAction(quit);
    connect(quit, &QAction::triggered, this, &QWidget::close);
}

Custom example

KDMacTouchBar from example

There has also been some investigation into custom QML views within the touch bar, although this is not currently included in KDMacTouchBar. Stay tuned for news when it eventually comes out in the near future!

 

 

About KDAB

KDAB is a consulting company offering a wide variety of expert services in Qt, C++ and 3D/OpenGL and providing training courses in:

KDAB believes that it is critical for our business to contribute to the Qt framework and C++ thinking, to keep pushing these technologies forward to ensure they remain competitive.

FacebookTwitterLinkedInEmail

Categories: KDAB on Qt

Leave a Reply

Your email address will not be published. Required fields are marked *