Skip to content

Qt Input Method – Virtual Keyboard Implementing an out-of-process virtual keyboard for text input in Qt apps

In the last episode of this blog series we learned about the overall concepts of input methods in Qt, with a look behind the scenes to see how a key press event from the native windowing system travels through the Qt input stack until it appears on screen inside a QLineEdit. In that context, the input method was used to allow the user to modify the input (e.g. composing a Chinese character sequence from Latin1 input).

Today we want to shed some light on another use case of the input method system, namely how to implement an out-of-process virtual keyboard that can be used to feed text input to arbitrary Qt-based applications.

Why do we need a virtual keyboard?

Believe it or not, there are devices out there which do not have a hardware keyboard attached (you might be holding one in your hand right now, while reading these lines ;)): mobile phones, tablets, kiosk terminals, to name just a few of them. The virtual keyboard (or sometimes called on-screen keyboard), is an application that runs alongside the other applications on the device. Whenever the user wants to input some text for the other applications, the virtual keyboard pops up a window that imitates the keys of a hardware keyboard. The user can now click the key buttons and the virtual keyboard application will convert those to key events, which will be sent to the application window that currently has the input focus. The receiving application processes the events like normal key events, so whether a hardware keyboard or a virtual keyboard is used should be opaque to it.

How do we implement a virtual keyboard with Qt?

There are actually two ways to implement a virtual keyboard with Qt: in-process and out-of-process.

For the in-process approach, the virtual keyboard becomes just another QWidget or QtQuick Item that shows the keyboard buttons, reacts to user interaction and delivers the synthesized QKeyEvents to the application’s event loop. The advantage of this approach is that it is very easy to implement, since no inter-process communication between the keyboard and the application is needed. The disadvantage, however, is that every application has to store its own instance of the virtual keyboard and the state of all these instances (visibility, activity etc.) might somehow need to be synchronized between applications.

The out-of-process approach, on the other hand, allows for a single instance of the virtual keyboard to be shared between all other applications, so no synchronization between multiple virtual keyboard instances is necessary. This requires you to come up with an inter-process communication mechanism between the global virtual keyboard instance and all the applications that want to use it.

In today’s blog post, we’ll go for the out-of-process approach and use DBus as the IPC mechanism, since it requires little code to integrate it with Qt applications and has already proved to work for other input method systems (IBus).

The keyboard application

Our keyboard application is based on Qt Widgets, to minimise the amount of code to write, but the concepts can be adopted to a QtQuick based UI wholesale. The actual UI is really basic, just a QGridLayout with a couple of buttons inside. There is one button for each number, one for each Latin character and a Backspace and Enter button. For simplicity we omit Shift and CapsLock keys (and therefore the functionality of entering upper case characters), implementing that is left as an exercise for the reader ;).

Keyboard UI

The source code of the main.cpp looks like that:

#include <QApplication>
#include <QDBusConnection>

#include "keyboard.h"

int main(int argc, char **argv)
{
    QApplication app(argc, argv);

    if (!QDBusConnection::sessionBus().registerService("com.kdab.inputmethod")) {
        qFatal("Unable to register at DBus");
        return 1;
    }

    Keyboard keyboard;

    if (!QDBusConnection::sessionBus().registerObject("/VirtualKeyboard", &keyboard, QDBusConnection::ExportAllSignals | QDBusConnection::ExportAllSlots)) {
        qFatal("Unable to register object at DBus");
        return 1;
    }

    return app.exec();
}

In the first three lines we include the headers for the classes we want to use: QApplication for the event loop, QDBusConnection to make this application accessible via DBus and keyboard.h, which provides the keyboard UI. In line 11 we try to register our application at the session bus, under the unique name ‘com.kdab.inputmethod’. If that fails, then something is wrong with DBus, so there is no point in running the application, because it won’t be reachable by other applications. In line 16 we create an instance of our keyboard UI, which is encapsulated inside the Keyboard class. Note that we don’t call show() on the Keyboard object here, so after startup, the application won’t show up any window. In line 18 we publish the Keyboard object under the path ‘/VirtualKeyboard’ and make all its public slots and signals accessible. That is all that needs to be done in main.cpp, now let’s have a look at keyboard.h:

class Keyboard : public QWidget
{
    Q_OBJECT

public:
    explicit Keyboard(QWidget *parent = Q_NULLPTR);

public slots:
    void showKeyboard();
    void hideKeyboard();
    bool keyboardVisible() const;

signals:
    void specialKeyClicked(int key);
    void keyClicked(const QString &text);

private slots:
    void buttonClicked(int key);
};

Our Keyboard class inherits from QWidget, so that it can be shown as a window on the screen. Except from a constructor, where all the UI initialization is done, it provides three public slots to show up the keyboard UI, hide it again and query its current visibility. Additionally there are two signals keyClicked() and specialKeyClicked(), which are emitted whenever the user clicked a number or letter button (keyClicked()) or the Backspace or Enter button (specialKeyClicked()).

Keyboard::Keyboard(QWidget *parent)
    : QWidget(parent)
{
    setWindowFlags(Qt::WindowDoesNotAcceptFocus | Qt::Tool |
                   Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);

    QGridLayout *gridLayout = new QGridLayout(this);

    QSignalMapper *mapper = new QSignalMapper(this);
    connect(mapper, SIGNAL(mapped(int)), SLOT(buttonClicked(int)));

    int row = 0;
    int column = 0;

    for (int i = 0; i < layoutSize; ++i) {
        if (keyboardLayout[i].key == NEXT_ROW_MARKER) {
            row++;
            column = 0;
            continue;
        }

        QPushButton *button = new QPushButton;
        button->setFixedWidth(40);
        button->setText(QString::fromLatin1(keyboardLayout[i].label));

        mapper->setMapping(button, keyboardLayout[i].key);
        connect(button, SIGNAL(clicked()), mapper, SLOT(map()));

        gridLayout->addWidget(button, row, column);
        column++;
    }
}

To ensure that interacting with the keyboard window does not take away the focus from the application window that uses the virtual keyboard, we have to set the Qt::WindowDoesNotAcceptFocus flag. From line 8 on we assemble the UI by creating the QGridLayout and filling it with the keyboard buttons. To avoid code duplication, we store the properties of the buttons (key code and label) in an array and iterate over it in the for-loop in line 16. For each entry we create a QPushButton with a fixed width and set the key label as button text. Since all button clicks should be handled in a central place, we use the QSignalMapper to invoke the private buttonClicked(int key) slot, whenever one of the QPushButtons is clicked. The ‘key’ parameter is the corresponding Qt::Key as defined in the ‘keyboardLayout’ array, which is defined as the following:

#define NEXT_ROW_MARKER 0

struct KeyboardLayoutEntry{
    int key;
    const char *label;
};

KeyboardLayoutEntry keyboardLayout[] = {
    { Qt::Key_1, "1" },
    { Qt::Key_2, "2" },
    { Qt::Key_3, "3" },
    { Qt::Key_4, "4" },
    { Qt::Key_5, "5" },
    { Qt::Key_6, "6" },
    { Qt::Key_7, "7" },
    { Qt::Key_8, "8" },
    { Qt::Key_9, "9" },
    { Qt::Key_0, "0" },
    { Qt::Key_Backspace, "<-" },
    { NEXT_ROW_MARKER, 0 },
    { Qt::Key_Q, "q" },
    { Qt::Key_W, "w" },
    ...
};

const static int layoutSize = (sizeof(keyboardLayout) /
                               sizeof(KeyboardLayoutEntry));

So every entry has the Qt::Key code and the label that should be used. Additionally there are some special marker entries with key code ‘NEXT_ROW_MARKER’, which just ensure that the following buttons will end up on the next line in our QGridLayout.

Now what happens if the user clicks on one of the QPushButtons? The buttonClicked() slot is invoked:

void Keyboard::buttonClicked(int key)
{
    if ((key == Qt::Key_Enter) || (key == Qt::Key_Backspace))
        emit specialKeyClicked(key);
    else
        emit keyClicked(keyToCharacter(key));
}

If the pressed key is Backspace or Enter, the specialKeyClicked() signal is emitted, otherwise the key code is mapped to a character and the keyClicked() signal is emitted with that character as parameter. To do the mapping, the helper method keyToCharacter() is invoked, which is defined as follows:

static QString keyToCharacter(int key)
{
    for (int i = 0; i < layoutSize; ++i) {
        if (keyboardLayout[i].key == key)
            return QString::fromLatin1(keyboardLayout[i].label);
    }

    return QString();
}

In this simple keyboard implementation, we just return the label of the button (so a lower-case character or a number). In a more advanced version, you would have to take pressed modifier keys into consideration to map to upper-case or other special characters.

The implementation for the remaining public slots is straightforward. They simply forward the requests to the corresponding methods in the QWidget base class.

void Keyboard::showKeyboard()
{
    QWidget::show();
}

void Keyboard::hideKeyboard()
{
    QWidget::hide();
}

bool Keyboard::keyboardVisible() const
{
    return QWidget::isVisible();
}

To summarize: We now have a keyboard UI application that is accessible via DBus through the name “com.kdab.inputmethod/VirtualKeyboard”. It provides methods to show it on screen, hide it from screen and ask for its current visibility. Additionally, that application emits the two signals specialKeyClicked() and keyClicked() (also via DBus) whenever the user clicks on one of the QPushButtons.

A simple test as to whether the keyboard UI works as expected, can be done by starting the application and then using qdbusviewer to inspect its DBus interface, invoke the exported slots and log the signal emissions.

qdbusviewer

Now that we have the virtual keyboard, let’s have a look at the corresponding input method implementation…

The Qt Input Method plugin

In the previous post [add link] of this series we learned that the communication between the Qt text input components and the input method system is done through the public front end class QInputMethod and the private back end class QPlatformInputContext. If we want to provide our own input method, we have to do two things:

  1. Implement a custom version of QPlatformInputContext subclass
  2. Implement a QPlatformInputContextPlugin, which provides that subclass to Qt

Let’s start with the latter by having a look at the main.cpp of the plugin:

class QVkImPlatformInputContextPlugin : public QPlatformInputContextPlugin
{
    Q_OBJECT
    Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QPlatformInputContextFactoryInterface" FILE "vkim.json")

public:
    QVkImPlatformInputContext *create(const QString&, const QStringList&) Q_DECL_OVERRIDE;
};

QVkImPlatformInputContext *QVkImPlatformInputContextPlugin::create(const QString& system, const QStringList& paramList)
{
    Q_UNUSED(paramList);

    if (system == QLatin1String("vkim")) {
        return new QVkImPlatformInputContext;
    }

    return 0;
}

We declare a new class QVkImPlatformInputContextPlugin which inherits from QPlatformInputContextPlugin and we reimplement the virtual method create(). The plugin meta data are stored in the external file ‘vkim.json’, which just contains the following lines:

{
    "Keys": [ "vkim" ]
}

The term ‘vkim’ is short for ‘virtual keyboard input method’ and is used as an identifier for our input method plugin. We will see later on where it is needed.

In the implementation of QVkImPlatformInputContextPlugin::create() we check if the requested object has that identifier and return a new instance of our custom class QVkImPlatformInputContext in this case. QVkImPlatformInputContext is our custom reimplementation of QPlatformInputContext with the following declaration:

class QVkImPlatformInputContext : public QPlatformInputContext
{
    Q_OBJECT

public:
    QVkImPlatformInputContext();
    ~QVkImPlatformInputContext();

    bool isValid() const Q_DECL_OVERRIDE;
    void setFocusObject(QObject *object) Q_DECL_OVERRIDE;

    void showInputPanel() Q_DECL_OVERRIDE;
    void hideInputPanel() Q_DECL_OVERRIDE;
    bool isInputPanelVisible() const Q_DECL_OVERRIDE;

private slots:
    void keyboardSpecialKeyClicked(int key);
    void keyboardKeyClicked(const QString &character);

private:
    QDBusInterface *m_keyboardInterface;

    QObject *m_focusObject;
};

It reimplements five virtual methods from QPlatformInputContext that have the following functionality:

  • isValid() is called by QPlatformInputContextFactory (the class that loads the plugin and invokes the create() method) to check if the input method is ready to use
  • setFocusObject() is called by QGuiApplication to inform the QPlatformInputContext about the object that currently has input focus
  • showInputPanel() is called by QInputMethod::show() to call up the keyboard UI if a text input field retrieves the focus
  • hideInputPanel() is called by QInputMethod::hide() to hide the keyboard UI if the current text input field loses focus
  • isInputPanelVisible() is called by QInputMethod::isVisible() to inform the application about the visibility state of the keyboard UI

Additionally there are the two private slots, keyboardSpecialKeyClicked() and keyboardKeyClicked(), which are invoked whenever we receive the corresponding signals from our keyboard UI application via DBus. The two member variables store a pointer to the DBus interface and a pointer to the current focus object in the application.

Now let’s have a look at the implementation of that class, where all the magic happens:

QVkImPlatformInputContext::QVkImPlatformInputContext()
    : m_focusObject(0)
{
    m_keyboardInterface = new QDBusInterface("com.kdab.inputmethod",
                                             "/VirtualKeyboard",
                                             "local.server.Keyboard",
                                             QDBusConnection::sessionBus(),
                                             this);

    connect(m_keyboardInterface, SIGNAL(keyClicked(QString)),
            SLOT(keyboardKeyClicked(QString)));
    connect(m_keyboardInterface, SIGNAL(specialKeyClicked(int)),
            SLOT(keyboardSpecialKeyClicked(int)));
}

Inside the constructor, the connection to the keyboard UI DBus interface is established. Here we have to specify the “com.kdab.inputmethod” application ID and “/VirtualKeyboard” path to point to the exported Keyboard object. Since our class needs to be informed about the buttons that the user clicked on the keyboard UI, we connect the two signals keyClicked() and specialKeyClicked() against the two private slots.

bool QVkImPlatformInputContext::isValid() const
{
    return m_keyboardInterface->isValid();
}

Inside the isValid() method we just return whether the DBus interface object is valid. If we couldn’t connect to the keyboard UI application, then our input method wouldn’t be of any use, so this test is sufficient.

void QVkImPlatformInputContext::setFocusObject(QObject *object)
{
    m_focusObject = object;
}

In case the QGuiApplication informs us about a new focus object, we store the pointer to it in the member variable, since we need it later on (see below).

void QVkImPlatformInputContext::showInputPanel()
{
    m_keyboardInterface->call("showKeyboard");
}

void QVkImPlatformInputContext::hideInputPanel()
{
    m_keyboardInterface->call("hideKeyboard");
}

When QInputMethod::show() or QInputMethod::hide() is invoked by the text input widgets (e.g. QLineEdit or QTextEdit), the showInputPanel() and hideInputPanel() methods are called, which forward these requests via the DBus interface to the keyboard UI process:

bool QVkImPlatformInputContext::isInputPanelVisible() const
{
    const QDBusReply<bool> reply = m_keyboardInterface->call("keyboardVisible");

    if (reply.isValid())
        return reply.value();
    else
        return false;
}

The very same approach is taken for QInputMethod::isVisible(), which invokes isInputPanelVisible(). In that case we also invoke the remote function in the keyboard UI process via DBus, but this time, we have to process the return value as well:

void QVkImPlatformInputContext::keyboardKeyClicked(const QString &characters)
{
    if (!m_focusObject)
        return;

    QInputMethodEvent event;
    event.setCommitString(characters);

    QGuiApplication::sendEvent(m_focusObject, &event);
}

Now we come to the part where our custom QPlatformInputContext forwards the key clicks, as received from the keyboard UI application, to the user application. For textual input that is done with the QInputMethodEvent. So if there is a text input widget that currently has the input focus (m_focusObject != null) we set the typed in characters as commit string on the event and send it to the object.

void QVkImPlatformInputContext::keyboardSpecialKeyClicked(int key)
{
    if (!m_focusObject)
        return;

    if (key == Qt::Key_Enter) {
        QKeyEvent *pressEvent = new QKeyEvent(QEvent::KeyPress,
                                              Qt::Key_Enter,
                                              Qt::NoModifier);

        QGuiApplication::postEvent(m_focusObject, pressEvent);

        QKeyEvent *releaseEvent = new QKeyEvent(QEvent::KeyRelease,
                                                Qt::Key_Enter,
                                                Qt::NoModifier);

        QGuiApplication::postEvent(m_focusObject, releaseEvent);
    } else if (key == Qt::Key_Backspace) {
        QKeyEvent *pressEvent = new QKeyEvent(QEvent::KeyPress,
                                              Qt::Key_Backspace,
                                              Qt::NoModifier);

        QGuiApplication::postEvent(m_focusObject, pressEvent);

        QKeyEvent *releaseEvent = new QKeyEvent(QEvent::KeyRelease,
                                                Qt::Key_Backspace,
                                                Qt::NoModifier);

        QGuiApplication::postEvent(m_focusObject, releaseEvent);
    }
}

For every non-textual input, in our case the Backspace and Enter key, we synthesize QKeyEvents for the press and release event and post them to the focus object through the event loop. While using a QKeyEvent to deliver, the Enter key is required. The Backspace functionality (removing the character on the left side of the input cursor) could have been implemented with a QInputMethodEvent as well:

    QInputMethodEvent event;
    event.setCommitString("", -1, 1);

    QGuiApplication::sendEvent(m_focusObject, &event);

Since we are passing values unequal to 0 to the second and third parameter of setCommitString(), the QInputEvent won’t append the given characters to the content of the input widget, but will replace 1 character (replaceLength in 3rd parameter) at position -1 (replaceFrom in 2nd parameter), which means 1 character left of the input cursor position, with an empty string (first parameter).

Bringing it all together

Now that we have the virtual keyboard and the input method plugin that communicates with it, let’s have a look at how to use it with a real Qt application. By default, the used QPA plugin provides an input method for the system, so if we want to use our own one, we have to tell Qt about that explicitly, by setting the environment variable QT_IM_MODULE to the identifier of the input method. In our case that identifier is ‘vkim’, the very same value we stored inside vkim.json as meta data for the input method plugin.

To use Qt Designer with our virtual keyboard just execute the following commands on the Linux command line:

# start the keyboard UI application
./server

# set the environment variable
export QT_IM_MODULE=vkim

# run any Qt application
designer

Now as soon as you click in a text input field in Qt Designer, the keyboard UI will show up: im_in_action

Further improvements

As mentioned before, this example implementation is really basic, to show you the concepts behind that technique without getting lost in details. For a real virtual keyboard that can be used in a production system, you might want to add the following functionality:

  • multiple keyboard layouts That basically means showing different labels on the keyboard buttons, depending on the configured layout, and returning these characters in the keyToCharacter() function
  • positioning of keyboard window In the current implementation, the position of the keyboard window on screen is selected by the window manager, which normally prevents windows from overlapping. For the virtual keyboard, however, we might want to open it near (below or above) the text input widget, so that we don’t have to move the mouse cursor across the whole screen. With QWidget::mapToGlobal() we can determine the position of the focus widget on the screen and place the UI accordingly, by adding a new ‘void setPosition(int x, int y)’ method to the DBus interface of the Keyboard class.

Resources

The source code of the example can be found at https://github.com/KDAB/virtual-keyboard-demo.

View our ‘Widgets and more’ video series

Yes, widgets are still alive and kicking. In the many years we have worked with them, we have gathered quite a number of tips and tricks that we’d love to share with you.

Welcome to our brand new video series about...Qt Widgets! Yes, widgets are still alive and kicking. In the many years we have worked with them, we have gathered quite a number of tips and tricks that we'd love to share with you.

Whether it's some handy snippet in C++ or a hidden button in a graphical tool, these suggestions will make your development life considerably easier.
In this first video, we will show you a few ways to improve your workflow when using a QGridLayout inside Qt Designer. Sounds simple, doesn't it? Well, there are a few subtleties involved.

The example code showcased in this video is available here: https://github.com/KDAB/kdabtv

All Qt Widgets and more videos:
https://www.youtube.com/playlist?list=PL6CJYn40gN6gf-G-o6syFwGrtq3kItEqI

About the host:
The video is presented by Jesper Pedersen, who started with Qt back when Qt was widgets only and the version was 1.44, which gives him 21 years of experience with Qt. Since 2000 he has taught almost 100 Qt classes, ranging from Qt Widgets to QML. Heck, Jesper even taught a few classes on QTopia Core — Trolltech's initial attempt at creating a phone stack. Today Jesper holds a fancy business title, but that doesn't prevent him from coding both in his job and in his spare time.

About KDAB:
KDAB offers experienced software experts to help you deliver functional, high-performing and innovative software across embedded, mobile and desktop platforms for projects using C++, Qt, QML/Qt Quick, OpenGL, Qt 3D and more.  https://www.kdab.com/software-services

KDAB experts regularly take time out to deliver KDAB’s world class training, in-house or at open enrollment courses around the world. We are the market leaders for training in Qt, OpenGL and C++.

Contact us to find out more at training@kdab.com or visit our website: https://www.kdab.com/software-services/scheduled-training/

We are about 90 people, located all around the world. Our Head Office is in Sweden and we have other offices in Germany, France, the UK and the USA. https://www.kdab.com/about/contact/
GridLayout in Qt Designer

Welcome to our brand new video series about...Qt Widgets! Yes, widgets are still alive and kicking. In the many years we have worked with them, we have gathered quite a number of tips and tricks that we'd love to share with you.

Whether it's some handy snippet in C++ or a hidden button in a graphical tool, these suggestions will make your development life considerably easier.
In this first video, we will show you a few ways to improve your workflow when using a QGridLayout inside Qt Designer. Sounds simple, doesn't it? Well, there are a few subtleties involved.

The example code showcased in this video is available here: https://github.com/KDAB/kdabtv

The video is presented by Jesper Pedersen, who started with Qt back when Qt was widgets only and the version was 1.44, which gives him 21 years of experience with Qt. Since 2000 he has taught almost 100 Qt classes, ranging from Qt Widgets to QML. Heck, Jesper even taught a few classes on QTopia Core — Trolltech's initial attempt at creating a phone stack. Today Jesper holds a fancy business title, but that doesn't prevent him from coding both in his job and in his spare time.

About KDAB:
KDAB offers experienced software experts to help you deliver functional, high-performing and innovative software across embedded, mobile and desktop platforms for projects using C++, Qt, QML/Qt Quick, OpenGL, Qt 3D and more. https://www.kdab.com/software-services

KDAB experts regularly take time out to deliver KDAB’s world class training, in-house or at open enrollment courses around the world. We are the market leaders for training in Qt, OpenGL and C++.

Contact us to find out more at training@kdab.com or visit our website: https://www.kdab.com/software-services/scheduled-training/

We are about 90 people, located all around the world. Our Head Office is in Sweden and we have other offices in Germany, France, the UK and the USA. https://www.kdab.com/about/contact/

354 34

YouTube Video UEw2Q0pZbjQwZ042Z2YtRy1vNnN5RndHcnRxM2tJdEVxSS41NkI0NEY2RDEwNTU3Q0M2

GridLayout in Qt Designer

Let's revisit Qt Designer once more, this time to discuss combo boxes. Mapping a QComboBox's entry to a specific value is easy in C++, but not so easy when the combo box is populated from within Qt Designer. How do we improve the situation?

The example code showcased in this video is available here: https://github.com/KDAB/kdabtv/tree/master/Qt-Widgets-and-more/ComboBoxSetup

All Qt Widgets and more videos:
https://www.youtube.com/playlist?list=PL6CJYn40gN6gf-G-o6syFwGrtq3kItEqI

About the host:
The video is presented by Jesper Pedersen, who started with Qt back when Qt was widgets only and the version was 1.44, which gives him 21 years of experience with Qt. Since 2000 he has taught almost 100 Qt classes, ranging from Qt Widgets to QML. Heck, Jesper even taught a few classes on QTopia Core — Trolltech's initial attempt at creating a phone stack. Today Jesper holds a fancy business title, but that doesn't prevent him from coding both in his job and in his spare time.

About KDAB:
KDAB offers experienced software experts to help you deliver functional, high-performing and innovative software across embedded, mobile and desktop platforms for projects using C++, Qt, QML/Qt Quick, OpenGL, Qt 3D and more.  https://www.kdab.com/software-services

KDAB experts regularly take time out to deliver KDAB’s world class training, in-house or at open enrollment courses around the world. We are the market leaders for training in Qt, OpenGL and C++.

Contact us to find out more at training@kdab.com or visit our website: https://www.kdab.com/software-services/scheduled-training/

We are about 90 people, located all around the world. Our Head Office is in Sweden and we have other offices in Germany, France, the UK and the USA. https://www.kdab.com/about/contact/
Populating a Combobox from Qt Designer

Let's revisit Qt Designer once more, this time to discuss combo boxes. Mapping a QComboBox's entry to a specific value is easy in C++, but not so easy when the combo box is populated from within Qt Designer. How do we improve the situation?

The example code showcased in this video is available here: https://github.com/KDAB/kdabtv

The video is presented by Jesper Pedersen, who started with Qt back when Qt was widgets only and the version was 1.44, which gives him 21 years of experience with Qt. Since 2000 he has taught almost 100 Qt classes, ranging from Qt Widgets to QML. Heck, Jesper even taught a few classes on QTopia Core — Trolltech's initial attempt at creating a phone stack. Today Jesper holds a fancy business title, but that doesn't prevent him from coding both in his job and in his spare time.

About KDAB:
KDAB offers experienced software experts to help you deliver functional, high-performing and innovative software across embedded, mobile and desktop platforms for projects using C++, Qt, QML/Qt Quick, OpenGL, Qt 3D and more. https://www.kdab.com/software-services

KDAB experts regularly take time out to deliver KDAB’s world class training, in-house or at open enrollment courses around the world. We are the market leaders for training in Qt, OpenGL and C++.

Contact us to find out more at training@kdab.com or visit our website: https://www.kdab.com/software-services/scheduled-training/

We are about 90 people, located all around the world. Our Head Office is in Sweden and we have other offices in Germany, France, the UK and the USA. https://www.kdab.com/about/contact/

97 4

YouTube Video UEw2Q0pZbjQwZ042Z2YtRy1vNnN5RndHcnRxM2tJdEVxSS4yODlGNEE0NkRGMEEzMEQy

Populating a Combobox from Qt Designer

If you're submitting code for a review, there's nothing worse than getting nitpicked because you violated a style guideline of the project.
If you're doing the code review, there's nothing more annoying than nitpicking on small code style inconsistencies.

This is where clang-format can help you. Clang-format is a tool (based on the clang/LLVM compiler infrastructure) that can automatically reformat your source code. Not only can you run it manually to apply a given formatting, but you can set it up so that it automatically reformats the code when committing into git, or when saving in Qt Creator.

The example code showcased in this video is available here: 
https://github.com/KDAB/kdabtv/tree/master/Qt-Widgets-and-more/clang-format

All Qt Widgets and more videos:
https://www.youtube.com/playlist?list=PL6CJYn40gN6gf-G-o6syFwGrtq3kItEqI

About the host:
The video is presented by Jesper Pedersen, who started with Qt back when Qt was widgets only and the version was 1.44, which gives him 21 years of experience with Qt. Since 2000 he has taught almost 100 Qt classes, ranging from Qt Widgets to QML. Heck, Jesper even taught a few classes on QTopia Core — Trolltech's initial attempt at creating a phone stack. Today Jesper holds a fancy business title, but that doesn't prevent him from coding both in his job and in his spare time.

About KDAB:
KDAB offers experienced software experts to help you deliver functional, high-performing and innovative software across embedded, mobile and desktop platforms for projects using C++, Qt, QML/Qt Quick, OpenGL, Qt 3D and more.  https://www.kdab.com/software-services

KDAB experts regularly take time out to deliver KDAB’s world class training, in-house or at open enrollment courses around the world. We are the market leaders for training in Qt, OpenGL and C++.

Contact us to find out more at training@kdab.com or visit our website: https://www.kdab.com/software-services/scheduled-training/

We are about 90 people, located all around the world. Our Head Office is in Sweden and we have other offices in Germany, France, the UK and the USA. https://www.kdab.com/about/contact/
Using Clang-Format to Ensure Style Guidelines

If you're submitting code for a review, there's nothing worse than getting nitpicked because you violated some style guideline of the project.
If you're doing a code review, there's nothing more annoying than nitpicking on small code style inconsistencies.

This is where clang-format can help us. clang-format is a tool (based on the clang/LLVM compiler infrastructure) that can automatically reformat our source code. Not only we can run it manually to apply a given formatting, but we can set it up so that it automatically reformats the code when committing into git, or when saving in Qt Creator.

The example code showcased in this video is available here: https://github.com/KDAB/kdabtv

The video is presented by Jesper Pedersen, who started with Qt back when Qt was widgets only and the version was 1.44, which gives him 21 years of experience with Qt. Since 2000 he has taught almost 100 Qt classes, ranging from Qt Widgets to QML. Heck, Jesper even taught a few classes on QTopia Core — Trolltech's initial attempt at creating a phone stack. Today Jesper holds a fancy business title, but that doesn't prevent him from coding both in his job and in his spare time.

About KDAB:
KDAB offers experienced software experts to help you deliver functional, high-performing and innovative software across embedded, mobile and desktop platforms for projects using C++, Qt, QML/Qt Quick, OpenGL, Qt 3D and more. https://www.kdab.com/software-services

KDAB experts regularly take time out to deliver KDAB’s world class training, in-house or at open enrollment courses around the world. We are the market leaders for training in Qt, OpenGL and C++.

Contact us to find out more at training@kdab.com or visit our website: https://www.kdab.com/software-services/scheduled-training/

We are about 90 people, located all around the world. Our Head Office is in Sweden and we have other offices in Germany, France, the UK and the USA. https://www.kdab.com/about/contact/

141 12

YouTube Video UEw2Q0pZbjQwZ042Z2YtRy1vNnN5RndHcnRxM2tJdEVxSS41MjE1MkI0OTQ2QzJGNzNG

Using Clang-Format to Ensure Style Guidelines

Today's video falls in the proverbial "removing the pebble in one's shoes" category. We'll talk about headers in a QTableView. Were you ever slightly annoyed by the fact that you can click on a header and sort the table by the corresponding column, but then you cannot undo the sorting? Let's fix that!

The example code showcased in this video is available here: https://github.com/KDAB/kdabtv/tree/master/Qt-Widgets-and-more/HeaderSortingAdapter

All Qt Widgets and more videos:
https://www.youtube.com/playlist?list=PL6CJYn40gN6gf-G-o6syFwGrtq3kItEqI

About the host:
The video is presented by Jesper Pedersen, who started with Qt back when Qt was widgets only and the version was 1.44, which gives him 21 years of experience with Qt. Since 2000 he has taught almost 100 Qt classes, ranging from Qt Widgets to QML. Heck, Jesper even taught a few classes on QTopia Core — Trolltech's initial attempt at creating a phone stack. Today Jesper holds a fancy business title, but that doesn't prevent him from coding both in his job and in his spare time.

About KDAB:
KDAB offers experienced software experts to help you deliver functional, high-performing and innovative software across embedded, mobile and desktop platforms for projects using C++, Qt, QML/Qt Quick, OpenGL, Qt 3D and more.  https://www.kdab.com/software-services

KDAB experts regularly take time out to deliver KDAB’s world class training, in-house or at open enrollment courses around the world. We are the market leaders for training in Qt, OpenGL and C++.

Contact us to find out more at training@kdab.com or visit our website: https://www.kdab.com/software-services/scheduled-training/

We are about 90 people, located all around the world. Our Head Office is in Sweden and we have other offices in Germany, France, the UK and the USA. https://www.kdab.com/about/contact/
Un-sorting Headers in QTableView

Today's video falls in the proverbial "removing the pebble in one's shoes" category. We'll talk about headers in a QTableView. Were you ever slightly annoyed by the fact that you can click on a header and sort the table by the corresponding column, but then you cannot undo the sorting? Let's fix that!

The example code showcased in this video is available here: https://github.com/KDAB/kdabtv

The video is presented by Jesper Pedersen, who started with Qt back when Qt was widgets only and the version was 1.44, which gives him 21 years of experience with Qt. Since 2000 he has taught almost 100 Qt classes, ranging from Qt Widgets to QML. Heck, Jesper even taught a few classes on QTopia Core — Trolltech's initial attempt at creating a phone stack. Today Jesper holds a fancy business title, but that doesn't prevent him from coding both in his job and in his spare time.

About KDAB:
KDAB offers experienced software experts to help you deliver functional, high-performing and innovative software across embedded, mobile and desktop platforms for projects using C++, Qt, QML/Qt Quick, OpenGL, Qt 3D and more. https://www.kdab.com/software-services

KDAB experts regularly take time out to deliver KDAB’s world class training, in-house or at open enrollment courses around the world. We are the market leaders for training in Qt, OpenGL and C++.

Contact us to find out more at training@kdab.com or visit our website: https://www.kdab.com/software-services/scheduled-training/

We are about 90 people, located all around the world. Our Head Office is in Sweden and we have other offices in Germany, France, the UK and the USA. https://www.kdab.com/about/contact/

67 2

YouTube Video UEw2Q0pZbjQwZ042Z2YtRy1vNnN5RndHcnRxM2tJdEVxSS4wOTA3OTZBNzVEMTUzOTMy

Un-sorting Headers in QTableView

Remember this tip: when an application is being introspected by GammaRay, you can use Control + Shift + Mouse click on any of its widgets to select it for further inspection. This lets you check all the properties for the widget, its positioning, as well as simply get an answer to the question: of which class is this widget?

The example code showcased in this video is available here: https://github.com/KDAB/kdabtv

All Qt Widgets and more videos:
https://www.youtube.com/playlist?list=PL6CJYn40gN6gf-G-o6syFwGrtq3kItEqI

About the host:
The video is presented by Jesper Pedersen, who started with Qt back when Qt was widgets only and the version was 1.44, which gives him 21 years of experience with Qt. Since 2000 he has taught almost 100 Qt classes, ranging from Qt Widgets to QML. Heck, Jesper even taught a few classes on QTopia Core — Trolltech's initial attempt at creating a phone stack. Today Jesper holds a fancy business title, but that doesn't prevent him from coding both in his job and in his spare time.

About KDAB:
KDAB offers experienced software experts to help you deliver functional, high-performing and innovative software across embedded, mobile and desktop platforms for projects using C++, Qt, QML/Qt Quick, OpenGL, Qt 3D and more.  https://www.kdab.com/software-services

KDAB experts regularly take time out to deliver KDAB’s world class training, in-house or at open enrollment courses around the world. We are the market leaders for training in Qt, OpenGL and C++.

Contact us to find out more at training@kdab.com or visit our website: https://www.kdab.com/software-services/scheduled-training/

We are about 90 people, located all around the world. Our Head Office is in Sweden and we have other offices in Germany, France, the UK and the USA. https://www.kdab.com/about/contact/
Using GammaRay to Find the Class of an UI Element

Remember this tip: when an application is being introspected by GammaRay, you can use Control + Shift + Mouse click on any of its widgets to select it for further inspection. This lets you check all the properties for the widget, its positioning, as well as simply get an answer to the question: of which class is this widget?

The example code showcased in this video is available here: https://github.com/KDAB/kdabtv

The video is presented by Jesper Pedersen, who started with Qt back when Qt was widgets only and the version was 1.44, which gives him 21 years of experience with Qt. Since 2000 he has taught almost 100 Qt classes, ranging from Qt Widgets to QML. Heck, Jesper even taught a few classes on QTopia Core — Trolltech's initial attempt at creating a phone stack. Today Jesper holds a fancy business title, but that doesn't prevent him from coding both in his job and in his spare time.

About KDAB:
KDAB offers experienced software experts to help you deliver functional, high-performing and innovative software across embedded, mobile and desktop platforms for projects using C++, Qt, QML/Qt Quick, OpenGL, Qt 3D and more. https://www.kdab.com/software-services

KDAB experts regularly take time out to deliver KDAB’s world class training, in-house or at open enrollment courses around the world. We are the market leaders for training in Qt, OpenGL and C++.

Contact us to find out more at training@kdab.com or visit our website: https://www.kdab.com/software-services/scheduled-training/

We are about 90 people, located all around the world. Our Head Office is in Sweden and we have other offices in Germany, France, the UK and the USA. https://www.kdab.com/about/contact/

17 2

YouTube Video UEw2Q0pZbjQwZ042Z2YtRy1vNnN5RndHcnRxM2tJdEVxSS4xMkVGQjNCMUM1N0RFNEUx

Using GammaRay to Find the Class of an UI Element

We know that we should use layouts to arrange children widgets inside a container widget. Layouts do the right thing for us, automatically, except when... they don't! Sometimes, we need to fine tune some of the decisions that layouts take; usually, the one that they take wrong is deciding how much padding/margins should be applied to contents. Let's see how to fix it.

The example code showcased in this video is available here: https://github.com/KDAB/kdabtv/tree/master/Qt-Widgets-and-more/ContentsMargins

All Qt Widgets and more videos:
https://www.youtube.com/playlist?list=PL6CJYn40gN6gf-G-o6syFwGrtq3kItEqI

About the host:
The video is presented by Jesper Pedersen, who started with Qt back when Qt was widgets only and the version was 1.44, which gives him 21 years of experience with Qt. Since 2000 he has taught almost 100 Qt classes, ranging from Qt Widgets to QML. Heck, Jesper even taught a few classes on QTopia Core — Trolltech's initial attempt at creating a phone stack. Today Jesper holds a fancy business title, but that doesn't prevent him from coding both in his job and in his spare time.

About KDAB:
KDAB offers experienced software experts to help you deliver functional, high-performing and innovative software across embedded, mobile and desktop platforms for projects using C++, Qt, QML/Qt Quick, OpenGL, Qt 3D and more.  https://www.kdab.com/software-services

KDAB experts regularly take time out to deliver KDAB’s world class training, in-house or at open enrollment courses around the world. We are the market leaders for training in Qt, OpenGL and C++.

Contact us to find out more at training@kdab.com or visit our website: https://www.kdab.com/software-services/scheduled-training/

We are about 90 people, located all around the world. Our Head Office is in Sweden and we have other offices in Germany, France, the UK and the USA. https://www.kdab.com/about/contact/
Understanding Contents Margins in Qt Layouts

We know that we should use layouts to arrange chidren widgets inside a container widget. Layouts do the right thing for us automatically. Except when... they don't! Sometimes we need to fine tune some of the decisions that layouts take; usually, the one that they take wrong is deciding how much padding/margins should be applied to contents. Let's see how to fix it.

The example code showcased in this video is available here: https://github.com/KDAB/kdabtv

The video is presented by Jesper Pedersen, who started with Qt back when Qt was widgets only and the version was 1.44, which gives him 21 years of experience with Qt. Since 2000 he has taught almost 100 Qt classes, ranging from Qt Widgets to QML. Heck, Jesper even taught a few classes on QTopia Core — Trolltech's initial attempt at creating a phone stack. Today Jesper holds a fancy business title, but that doesn't prevent him from coding both in his job and in his spare time.

About KDAB:
KDAB offers experienced software experts to help you deliver functional, high-performing and innovative software across embedded, mobile and desktop platforms for projects using C++, Qt, QML/Qt Quick, OpenGL, Qt 3D and more. https://www.kdab.com/software-services

KDAB experts regularly take time out to deliver KDAB’s world class training, in-house or at open enrollment courses around the world. We are the market leaders for training in Qt, OpenGL and C++.

Contact us to find out more at training@kdab.com or visit our website: https://www.kdab.com/software-services/scheduled-training/

We are about 90 people, located all around the world. Our Head Office is in Sweden and we have other offices in Germany, France, the UK and the USA. https://www.kdab.com/about/contact/

44 2

YouTube Video UEw2Q0pZbjQwZ042Z2YtRy1vNnN5RndHcnRxM2tJdEVxSS41MzJCQjBCNDIyRkJDN0VD

Understanding Contents Margins in Qt Layouts

You've seen me constantly use GammaRay, when checking: item sizes, visibility, and layout margins. In this video, let me share with you a little trick: You can launch GammaRay right from within Qt Creator, with a convenient keyboard shortcut.

The example code showcased in this video is available here: https://github.com/KDAB/kdabtv

Link to the GammaRay Tutorials: https://www.youtube.com/playlist?list=PL6CJYn40gN6itybeSJb5FvRWOxVW5PCUX

All Qt Widgets and more videos:
https://www.youtube.com/playlist?list=PL6CJYn40gN6gf-G-o6syFwGrtq3kItEqI

About the host:
The video is presented by Jesper Pedersen, who started with Qt back when Qt was widgets only and the version was 1.44, which gives him 21 years of experience with Qt. Since 2000 he has taught almost 100 Qt classes, ranging from Qt Widgets to QML. Heck, Jesper even taught a few classes on QTopia Core — Trolltech's initial attempt at creating a phone stack. Today Jesper holds a fancy business title, but that doesn't prevent him from coding both in his job and in his spare time.

About KDAB:
KDAB offers experienced software experts to help you deliver functional, high-performing and innovative software across embedded, mobile and desktop platforms for projects using C++, Qt, QML/Qt Quick, OpenGL, Qt 3D and more.  https://www.kdab.com/software-services

KDAB experts regularly take time out to deliver KDAB’s world class training, in-house or at open enrollment courses around the world. We are the market leaders for training in Qt, OpenGL and C++.

Contact us to find out more at training@kdab.com or visit our website: https://www.kdab.com/software-services/scheduled-training/

We are about 90 people, located all around the world. Our Head Office is in Sweden and we have other offices in Germany, France, the UK and the USA. https://www.kdab.com/about/contact/
Starting the Application in GammaRay from Qt Creator

You've seen me constantly use GammaRay, when checking: item sizes, visibility, and layout margins. In this video, let me share with you a little trick: You can launch GammaRay right from within Qt Creator, with a convenient keyboard shortcut.

The example code showcased in this video is available here: https://github.com/KDAB/kdabtv

Link to the GammaRay Tutorials: https://www.youtube.com/playlist?list=PL6CJYn40gN6itybeSJb5FvRWOxVW5PCUX

The video is presented by Jesper Pedersen, who started with Qt back when Qt was widgets only and the version was 1.44, which gives him 21 years of experience with Qt. Since 2000 he has taught almost 100 Qt classes, ranging from Qt Widgets to QML. Heck, Jesper even taught a few classes on QTopia Core — Trolltech's initial attempt at creating a phone stack. Today Jesper holds a fancy business title, but that doesn't prevent him from coding both in his job and in his spare time.

About KDAB:
KDAB offers experienced software experts to help you deliver functional, high-performing and innovative software across embedded, mobile and desktop platforms for projects using C++, Qt, QML/Qt Quick, OpenGL, Qt 3D and more. https://www.kdab.com/software-services

KDAB experts regularly take time out to deliver KDAB’s world class training, in-house or at open enrollment courses around the world. We are the market leaders for training in Qt, OpenGL and C++.

Contact us to find out more at training@kdab.com or visit our website: https://www.kdab.com/software-services/scheduled-training/

We are about 90 people, located all around the world. Our Head Office is in Sweden and we have other offices in Germany, France, the UK and the USA. https://www.kdab.com/about/contact/

20 2

YouTube Video UEw2Q0pZbjQwZ042Z2YtRy1vNnN5RndHcnRxM2tJdEVxSS5DQUNERDQ2NkIzRUQxNTY1

Starting the Application in GammaRay from Qt Creator

Sometimes a view would like to have more data for a cell than what is in a cell. Examples include:

A view that offers special context menu entries if the cell contains an employee. The text in the cell itself might just be the employee's name, and from that alone, it would be very hard to come to the conclusion that the cell indeed holds an employee.

A delegate that shows an annotation symbol (think cut of corner like in excel) if the data behind the cell is annotated. Again the cell text does not reveal this information.

One way to implement this is for the view or delegate to reach out to the model in question using a regular function call, but that will break in case there are proxy models in between.

This video shows how to obtain the effect by using custom roles.

You can contact us regarding our services at info@kdab.com

All Qt Widgets and more videos:
https://www.youtube.com/playlist?list=PL6CJYn40gN6gf-G-o6syFwGrtq3kItEqI

About the host:
The video is presented by Jesper Pedersen, who started with Qt back when Qt was widgets only and the version was 1.44, which gives him 21 years of experience with Qt. Since 2000 he has taught almost 100 Qt classes, ranging from Qt Widgets to QML. Heck, Jesper even taught a few classes on QTopia Core — Trolltech's initial attempt at creating a phone stack. Today Jesper holds a fancy business title, but that doesn't prevent him from coding both in his job and in his spare time.

About KDAB:

KDAB offers experienced software experts to help you deliver functional, high-performing and innovative software across embedded, mobile and desktop platforms for projects using C++, Qt, QML/Qt Quick, OpenGL, Qt 3D and more.  https://www.kdab.com/software-services

KDAB experts regularly take time out to deliver KDAB’s world class training, in-house or at open enrollment courses around the world. We are the market leaders for training in Qt, OpenGL and C++.

Contact us to find out more at training@kdab.com or visit our website: https://www.kdab.com/software-services/scheduled-training/

We are about 90 people, located all around the world. Our Head Office is in Sweden and we have other offices in Germany, France, the UK and the USA. https://www.kdab.com/about/contact/
Communicating between a View/Delegate and a Model

Sometimes a view would like to have more data for a cell than what is in a cell, examples includes:

A view that offer special context menu entries if the cell contains an employee. The text in the cell itself might just be the employees name, and from that alone it would be very hard to come to the conclusion that this the cell indeed holds an employee.

A delegate which shows an annotation symbol (think cut of corner like in excel) if the data behind the cell is annotated. Again the cell text do not reveal this information.

One way to implement this is for the view or delegate to reach out to the model in question using a regular function call, but that will break in case there are proxy models in between.

This video shows how to obtain the effect by using custom roles.

The example code showcased in this video is available here: https://github.com/KDAB/kdabtv

You can contact us regarding our services at info@kdab.com

The video is presented by Jesper Pedersen, who started with Qt back when Qt was widgets only and the version was 1.44, which gives him 21 years of experience with Qt. Since 2000 he has taught almost 100 Qt classes, ranging from Qt Widgets to QML. Heck, Jesper even taught a few classes on QTopia Core — Trolltech's initial attempt at creating a phone stack. Today Jesper holds a fancy business title, but that doesn't prevent him from coding both in his job and in his spare time.

About KDAB:

KDAB offers experienced software experts to help you deliver functional, high-performing and innovative software across embedded, mobile and desktop platforms for projects using C++, Qt, QML/Qt Quick, OpenGL, Qt 3D and more. https://www.kdab.com/software-services

KDAB experts regularly take time out to deliver KDAB’s world class training, in-house or at open enrollment courses around the world. We are the market leaders for training in Qt, OpenGL and C++.

Contact us to find out more at training@kdab.com or visit our website: https://www.kdab.com/software-services/scheduled-training/

We are about 90 people, located all around the world. Our Head Office is in Sweden and we have other offices in Germany, France, the UK and the USA. https://www.kdab.com/about/contact/

99 20

YouTube Video UEw2Q0pZbjQwZ042Z2YtRy1vNnN5RndHcnRxM2tJdEVxSS40NzZCMERDMjVEN0RFRThB

Communicating between a View/Delegate and a Model

Got a stack of proxy models where there is a subtle bug somewhere in there? No worries --GammaRay to the rescue!

It can visualize the stack of models for you, but there is one thing you better remember in your code --watch this video to find out what it is! 🙂

Link to download GammaRay: https://www.kdab.com/development-resources/qt-tools/gammaray/

All Qt Widgets and more videos:
https://www.youtube.com/playlist?list=PL6CJYn40gN6gf-G-o6syFwGrtq3kItEqI

About the host:
The video is presented by Jesper Pedersen, who started with Qt back when Qt was widgets only and the version was 1.44, which gives him 21 years of experience with Qt. Since 2000 he has taught almost 100 Qt classes, ranging from Qt Widgets to QML. Heck, Jesper even taught a few classes on QTopia Core — Trolltech's initial attempt at creating a phone stack. Today Jesper holds a fancy business title, but that doesn't prevent him from coding both in his job and in his spare time.

About KDAB:
KDAB offers experienced software experts to help you deliver functional, high-performing and innovative software across embedded, mobile and desktop platforms for projects using C++, Qt, QML/Qt Quick, OpenGL, Qt 3D and more.  https://www.kdab.com/software-services

KDAB experts regularly take time out to deliver KDAB’s world class training, in-house or at open enrollment courses around the world. We are the market leaders for training in Qt, OpenGL and C++.

Contact us to find out more at training@kdab.com or visit our website: https://www.kdab.com/software-services/scheduled-training/

We are about 90 people, located all around the world. Our Head Office is in Sweden and we have other offices in Germany, France, the UK and the USA. https://www.kdab.com/about/contact/
Visualizing the Model Stack in GammaRay

Got a stack of proxy models where there is a subtle bug somewhere in there? No worries --GammaRay to the rescue!

It can visualize the stack of models for you, but there is one thing you better remember in your code --watch this video to find out what it is! 🙂

Link to download GammaRay: https://www.kdab.com/development-resources/qt-tools/gammaray/

The video is presented by Jesper Pedersen, who started with Qt back when Qt was widgets only and the version was 1.44, which gives him 21 years of experience with Qt. Since 2000 he has taught almost 100 Qt classes, ranging from Qt Widgets to QML. Heck, Jesper even taught a few classes on QTopia Core — Trolltech's initial attempt at creating a phone stack. Today Jesper holds a fancy business title, but that doesn't prevent him from coding both in his job and in his spare time.

About KDAB:
KDAB offers experienced software experts to help you deliver functional, high-performing and innovative software across embedded, mobile and desktop platforms for projects using C++, Qt, QML/Qt Quick, OpenGL, Qt 3D and more. https://www.kdab.com/software-services

KDAB experts regularly take time out to deliver KDAB’s world class training, in-house or at open enrollment courses around the world. We are the market leaders for training in Qt, OpenGL and C++.

Contact us to find out more at training@kdab.com or visit our website: https://www.kdab.com/software-services/scheduled-training/

We are about 90 people, located all around the world. Our Head Office is in Sweden and we have other offices in Germany, France, the UK and the USA. https://www.kdab.com/about/contact/

31 1

YouTube Video UEw2Q0pZbjQwZ042Z2YtRy1vNnN5RndHcnRxM2tJdEVxSS5EMEEwRUY5M0RDRTU3NDJC

Visualizing the Model Stack in GammaRay

Sometimes a view or delegate needs to ask the model providing the data (at the bottom of a proxy model stack) some questions.

In the previous video, 'Communicating between a View/Delegate and a Model'  (https://youtu.be/q6eOEz_UfTI), I showed how custom roles can be used for this.

However, if the data isn't related to a specific cell, a better approach might be to traverse the proxy models yourself, to get to the actual source model.
This video shows this approach.

Link to download KDReports: https://www.kdab.com/development-resources/qt-tools/kd-reports/

All Qt Widgets and more videos:
https://www.youtube.com/playlist?list=PL6CJYn40gN6gf-G-o6syFwGrtq3kItEqI

About the host:
The video is presented by Jesper Pedersen, who started with Qt back when Qt was widgets only and the version was 1.44, which gives him 21 years of experience with Qt. Since 2000 he has taught almost 100 Qt classes, ranging from Qt Widgets to QML. Heck, Jesper even taught a few classes on QTopia Core — Trolltech's initial attempt at creating a phone stack. Today Jesper holds a fancy business title, but that doesn't prevent him from coding both in his job and in his spare time.

About KDAB:
KDAB offers experienced software experts to help you deliver functional, high-performing and innovative software across embedded, mobile and desktop platforms for projects using C++, Qt, QML/Qt Quick, OpenGL, Qt 3D and more.  https://www.kdab.com/software-services

KDAB experts regularly take time out to deliver KDAB’s world class training, in-house or at open enrollment courses around the world. We are the market leaders for training in Qt, OpenGL and C++.

Contact us to find out more at training@kdab.com or visit our website: https://www.kdab.com/software-services/scheduled-training/

We are about 90 people, located all around the world. Our Head Office is in Sweden and we have other offices in Germany, France, the UK and the USA. https://www.kdab.com/about/contact/
Traversing Proxy Models to Get to the Source Model at the Bottom

Sometimes a view or delegate need to ask the model providing the data (at the bottom of a proxy model stack) some questions.

In the previous video 'Communicating between a View/Delegate and a Model': https://youtu.be/q6eOEz_UfTI I showed how custom roles can be used for this.

However, if the data isn't related to a specific cell, a better approach might be to traverse the proxy models yourself, to get to the actual source model.
This video shows this approach.

Link to download KDReports: https://www.kdab.com/development-resources/qt-tools/kd-reports/

The example code showcased in this video is available here: https://github.com/KDAB/kdabtv

The video is presented by Jesper Pedersen, who started with Qt back when Qt was widgets only and the version was 1.44, which gives him 21 years of experience with Qt. Since 2000 he has taught almost 100 Qt classes, ranging from Qt Widgets to QML. Heck, Jesper even taught a few classes on QTopia Core — Trolltech's initial attempt at creating a phone stack. Today Jesper holds a fancy business title, but that doesn't prevent him from coding both in his job and in his spare time.

About KDAB:
KDAB offers experienced software experts to help you deliver functional, high-performing and innovative software across embedded, mobile and desktop platforms for projects using C++, Qt, QML/Qt Quick, OpenGL, Qt 3D and more. https://www.kdab.com/software-services

KDAB experts regularly take time out to deliver KDAB’s world class training, in-house or at open enrollment courses around the world. We are the market leaders for training in Qt, OpenGL and C++.

Contact us to find out more at training@kdab.com or visit our website: https://www.kdab.com/software-services/scheduled-training/

We are about 90 people, located all around the world. Our Head Office is in Sweden and we have other offices in Germany, France, the UK and the USA. https://www.kdab.com/about/contact/

23 0

YouTube Video UEw2Q0pZbjQwZ042Z2YtRy1vNnN5RndHcnRxM2tJdEVxSS45ODRDNTg0QjA4NkFBNkQy

Traversing Proxy Models to Get to the Source Model at the Bottom

In this episode, I'll show how you can use your own custom types to communicate between a model and a delegate editing these custom types. My example is a Money class which contains a currency and an amount. The delegate will see Money instances, rather than parse them from their string representation.

NOTE: This video was filmed before Qt6 was out, and it seems that, contrary to rumors, the function registerConverter is still there: https://doc.qt.io/qt-6/qmetatype.html#registerConverter.

The example code showcased in this video is available here: https://github.com/KDAB/kdabtv/tree/master/Qt-Widgets-and-more/CustomDataTypesInModel

All Qt Widgets and more videos:
https://www.youtube.com/playlist?list=PL6CJYn40gN6gf-G-o6syFwGrtq3kItEqI

About the host:
The video is presented by Jesper Pedersen, who started with Qt back when Qt was widgets only and the version was 1.44, which gives him 21 years of experience with Qt. Since 2000 he has taught almost 100 Qt classes, ranging from Qt Widgets to QML. Heck, Jesper even taught a few classes on QTopia Core — Trolltech's initial attempt at creating a phone stack. Today Jesper holds a fancy business title, but that doesn't prevent him from coding both in his job and in his spare time.

About KDAB:
KDAB offers experienced software experts to help you deliver functional, high-performing and innovative software across embedded, mobile and desktop platforms for projects using C++, Qt, QML/Qt Quick, OpenGL, Qt 3D and more.  https://www.kdab.com/software-services

KDAB experts regularly take time out to deliver KDAB’s world class training, in-house or at open enrollment courses around the world. We are the market leaders for training in Qt, OpenGL and C++.

Contact us to find out more at training@kdab.com or visit our website: https://www.kdab.com/software-services/scheduled-training/

We are about 90 people, located all around the world. Our Head Office is in Sweden and we have other offices in Germany, France, the UK and the USA. https://www.kdab.com/about/contact/
Using Custom Types with Model/View

In this episode I'll show how you can use your own custom types to communicate between a model and a delegate editing these custom types. My example is a Money class which contains a currency and an amount, the delegate will see Money instances, rather than parse them from their string representation.

NOTE: This video was filmed before Qt6 was out and it seems that contrary to rumors the function registerConverter is still there: https://doc.qt.io/qt-6/qmetatype.html#registerConverter

The example code showcased in this video is available here: https://github.com/KDAB/kdabtv .

The video is presented by Jesper Pedersen, who started with Qt back when Qt was widgets only and the version was 1.44, which gives him 21 years of experience with Qt. Since 2000 he has taught almost 100 Qt classes, ranging from Qt Widgets to QML. Heck, Jesper even taught a few classes on QTopia Core — Trolltech's initial attempt at creating a phone stack. Today Jesper holds a fancy business title, but that doesn't prevent him from coding both in his job and in his spare time.

About KDAB:
KDAB offers experienced software experts to help you deliver functional, high-performing and innovative software across embedded, mobile and desktop platforms for projects using C++, Qt, QML/Qt Quick, OpenGL, Qt 3D and more. https://www.kdab.com/software-services

KDAB experts regularly take time out to deliver KDAB’s world class training, in-house or at open enrollment courses around the world. We are the market leaders for training in Qt, OpenGL and C++.

Contact us to find out more at training@kdab.com or visit our website: https://www.kdab.com/software-services/scheduled-training/

We are about 90 people, located all around the world. Our Head Office is in Sweden and we have other offices in Germany, France, the UK and the USA. https://www.kdab.com/about/contact/

63 2

YouTube Video UEw2Q0pZbjQwZ042Z2YtRy1vNnN5RndHcnRxM2tJdEVxSS41Mzk2QTAxMTkzNDk4MDhF

Using Custom Types with Model/View

As a developer, your toolbox should help you as much as possible, and you ought to invest the time it takes to figure out what is in there. This episodes gives you my top seven shortcuts in Qt Creator that help me save hours (OK, maybe just minutes) every single day, but, much more importantly, ensures I stay focused on whatever problem I'm solving right now.

Download our Qt Creator Reference Card that lists lots more useful shortcuts here: https://www.kdab.com/development-resources/qtcreator/

All Qt Widgets and more videos:
https://www.youtube.com/playlist?list=PL6CJYn40gN6gf-G-o6syFwGrtq3kItEqI

About the host:
The video is presented by Jesper Pedersen, who started with Qt back when Qt was widgets only and the version was 1.44, which gives him 21 years of experience with Qt. Since 2000 he has taught almost 100 Qt classes, ranging from Qt Widgets to QML. Heck, Jesper even taught a few classes on QTopia Core — Trolltech's initial attempt at creating a phone stack. Today Jesper holds a fancy business title, but that doesn't prevent him from coding both in his job and in his spare time.

About KDAB:
KDAB offers experienced software experts to help you deliver functional, high-performing and innovative software across embedded, mobile and desktop platforms for projects using C++, Qt, QML/Qt Quick, OpenGL, Qt 3D and more.  https://www.kdab.com/software-services

KDAB experts regularly take time out to deliver KDAB’s world class training, in-house or at open enrollment courses around the world. We are the market leaders for training in Qt, OpenGL and C++.

Contact us to find out more at training@kdab.com or visit our website: https://www.kdab.com/software-services/scheduled-training/

We are about 90 people, located all around the world. Our Head Office is in Sweden and we have other offices in Germany, France, the UK and the USA. https://www.kdab.com/about/contact/
Top 7 Shortcuts in Qt Creator

As a developer your toolbox should help you as much as possible, and you ought to invest the time it takes to figure out what is in there. This episodes gives you my top seven shortcuts in Qt Creator that helps me save hours (OK, maybe just minutes) every single day, but much more important ensures I stay focused on whatever problem I'm solving right now.

Download our Qt Creator Reference Card that lists lots more useful shortcuts here: https://www.kdab.com/development-resources/qtcreator/

The video is presented by Jesper Pedersen, who started with Qt back when Qt was widgets only and the version was 1.44, which gives him 21 years of experience with Qt. Since 2000 he has taught almost 100 Qt classes, ranging from Qt Widgets to QML. Heck, Jesper even taught a few classes on QTopia Core — Trolltech's initial attempt at creating a phone stack. Today Jesper holds a fancy business title, but that doesn't prevent him from coding both in his job and in his spare time.

About KDAB:
KDAB offers experienced software experts to help you deliver functional, high-performing and innovative software across embedded, mobile and desktop platforms for projects using C++, Qt, QML/Qt Quick, OpenGL, Qt 3D and more. https://www.kdab.com/software-services

KDAB experts regularly take time out to deliver KDAB’s world class training, in-house or at open enrollment courses around the world. We are the market leaders for training in Qt, OpenGL and C++.

Contact us to find out more at training@kdab.com or visit our website: https://www.kdab.com/software-services/scheduled-training/

We are about 90 people, located all around the world. Our Head Office is in Sweden and we have other offices in Germany, France, the UK and the USA. https://www.kdab.com/about/contact/

118 6

YouTube Video UEw2Q0pZbjQwZ042Z2YtRy1vNnN5RndHcnRxM2tJdEVxSS5EQUE1NTFDRjcwMDg0NEMz

Top 7 Shortcuts in Qt Creator

In my code I have a lot of custom classes I use with model/view, including Money, PercentageValue, TimeValue just to name a few.

For years I've written code like this in my data methods of QAbstractItemModel subclasses:
return QVariant::fromValue(cost); // cost is an instance of the class Money
In this short video you will learn a very simple trick to avoid this.

The example code showcased in this video is available here: 
https://github.com/KDAB/kdabtv/tree/master/Qt-Widgets-and-more/CustomTypesAndVariants
and https://github.com/KDAB/kdabtv/tree/master/Qt-Widgets-and-more/VariantConverters

All Qt Widgets and more videos:
https://www.youtube.com/playlist?list=PL6CJYn40gN6gf-G-o6syFwGrtq3kItEqI

About the host:
The video is presented by Jesper Pedersen, who started with Qt back when Qt was widgets only and the version was 1.44, which gives him 21 years of experience with Qt. Since 2000 he has taught almost 100 Qt classes, ranging from Qt Widgets to QML. Heck, Jesper even taught a few classes on QTopia Core — Trolltech's initial attempt at creating a phone stack. Today Jesper holds a fancy business title, but that doesn't prevent him from coding both in his job and in his spare time.

About KDAB:
KDAB offers experienced software experts to help you deliver functional, high-performing and innovative software across embedded, mobile and desktop platforms for projects using C++, Qt, QML/Qt Quick, OpenGL, Qt 3D and more.  https://www.kdab.com/software-services

KDAB experts regularly take time out to deliver KDAB’s world class training, in-house or at open enrollment courses around the world. We are the market leaders for training in Qt, OpenGL and C++.

Contact us to find out more at training@kdab.com or visit our website: https://www.kdab.com/software-services/scheduled-training/

We are about 90 people, located all around the world. Our Head Office is in Sweden and we have other offices in Germany, France, the UK and the USA. https://www.kdab.com/about/contact/
Avoiding QVariant::fromValue around your Own Types

In my code I have a lot of custom classes I use with model/view, including Money, PercentageValue, TimeValue just to name a few.

For years I've written code like this in my data methods of QAbstractItemModel subclasses:
return QVariant::fromValue(cost); // cost is an instance of the class Money
In this short video you will learn a very simple trick to avoid this.

The example code showcased in this video is available here: https://github.com/KDAB/kdabtv

The video is presented by Jesper Pedersen, who started with Qt back when Qt was widgets only and the version was 1.44, which gives him 21 years of experience with Qt. Since 2000 he has taught almost 100 Qt classes, ranging from Qt Widgets to QML. Heck, Jesper even taught a few classes on QTopia Core — Trolltech's initial attempt at creating a phone stack. Today Jesper holds a fancy business title, but that doesn't prevent him from coding both in his job and in his spare time.

About KDAB:
KDAB offers experienced software experts to help you deliver functional, high-performing and innovative software across embedded, mobile and desktop platforms for projects using C++, Qt, QML/Qt Quick, OpenGL, Qt 3D and more. https://www.kdab.com/software-services

KDAB experts regularly take time out to deliver KDAB’s world class training, in-house or at open enrollment courses around the world. We are the market leaders for training in Qt, OpenGL and C++.

Contact us to find out more at training@kdab.com or visit our website: https://www.kdab.com/software-services/scheduled-training/

We are about 90 people, located all around the world. Our Head Office is in Sweden and we have other offices in Germany, France, the UK and the USA. https://www.kdab.com/about/contact/

50 6

YouTube Video UEw2Q0pZbjQwZ042Z2YtRy1vNnN5RndHcnRxM2tJdEVxSS41QTY1Q0UxMTVCODczNThE

Avoiding QVariant::fromValue around your Own Types

It is possible to have your own document templates in Qt Creator; learn in these four videos how to set that up.

In this first episode, I will create a simple template for new classes, based on the "C++ class" template. Further, I'll explain how to use macros and show the one expanding into the class name specified in the "new file" dialog.

Link to Qt Documentation: https://doc.qt.io/qtcreator/creator-project-wizards.html

The resulting template for these four episodes is in github. You can download it here: https://github.com/KDAB/kdabtv/tree/master/Qt-Widgets-and-more/QtCreatorFileTemplates

All Qt Widgets and more videos:
https://www.youtube.com/playlist?list=PL6CJYn40gN6gf-G-o6syFwGrtq3kItEqI

About the host:
The video is presented by Jesper Pedersen, who started with Qt back when Qt was widgets only and the version was 1.44, which gives him 21 years of experience with Qt. Since 2000 he has taught almost 100 Qt classes, ranging from Qt Widgets to QML. Heck, Jesper even taught a few classes on QTopia Core — Trolltech's initial attempt at creating a phone stack. Today Jesper holds a fancy business title, but that doesn't prevent him from coding both in his job and in his spare time.

About KDAB:
KDAB offers experienced software experts to help you deliver functional, high-performing and innovative software across embedded, mobile and desktop platforms for projects using C++, Qt, QML/Qt Quick, OpenGL, Qt 3D and more.  https://www.kdab.com/software-services

KDAB experts regularly take time out to deliver KDAB’s world class training, in-house or at open enrollment courses around the world. We are the market leaders for training in Qt, OpenGL and C++.

Contact us to find out more at training@kdab.com or visit our website: https://www.kdab.com/software-services/scheduled-training/

We are about 90 people, located all around the world. Our Head Office is in Sweden and we have other offices in Germany, France, the UK and the USA. https://www.kdab.com/about/contact/
Document Templates in Qt Creator - Part 1

It is possible to have your own document templates in Qt Creator, learn in these four videos how to set that up.

In this first episode, I will create a simple template for new classes based on the "C++ class" template. Further, I'll explain how to use macros, and show the one expanding into the class name specified in the "new file" dialog.

Link to Qt Documentation: https://doc.qt.io/qtcreator/creator-project-wizards.html

The resulting template for these four episodes is in github. You can download it here https://github.com/KDAB/kdabtv

The video is presented by Jesper Pedersen, who started with Qt back when Qt was widgets only and the version was 1.44, which gives him 21 years of experience with Qt. Since 2000 he has taught almost 100 Qt classes, ranging from Qt Widgets to QML. Heck, Jesper even taught a few classes on QTopia Core — Trolltech's initial attempt at creating a phone stack. Today Jesper holds a fancy business title, but that doesn't prevent him from coding both in his job and in his spare time.

About KDAB:
KDAB offers experienced software experts to help you deliver functional, high-performing and innovative software across embedded, mobile and desktop platforms for projects using C++, Qt, QML/Qt Quick, OpenGL, Qt 3D and more. https://www.kdab.com/software-services

KDAB experts regularly take time out to deliver KDAB’s world class training, in-house or at open enrollment courses around the world. We are the market leaders for training in Qt, OpenGL and C++.

Contact us to find out more at training@kdab.com or visit our website: https://www.kdab.com/software-services/scheduled-training/

We are about 90 people, located all around the world. Our Head Office is in Sweden and we have other offices in Germany, France, the UK and the USA. https://www.kdab.com/about/contact/

34 2

YouTube Video UEw2Q0pZbjQwZ042Z2YtRy1vNnN5RndHcnRxM2tJdEVxSS4yMUQyQTQzMjRDNzMyQTMy

Document Templates in Qt Creator - Part 1

It is possible to have your own document templates in Qt Creator. Learn, in these four videos, how to set that up.
In this episode, I'll show you how to add a new file (namely, a .ui file) to the set of files generated, which, among other things, will teach us a bit more about how the macro system works.

The resulting template for these four episodes is in github. You can download it here https://github.com/KDAB/kdabtv/tree/master/Qt-Widgets-and-more/QtCreatorFileTemplates

All Qt Widgets and more videos:
https://www.youtube.com/playlist?list=PL6CJYn40gN6gf-G-o6syFwGrtq3kItEqI

About the host:
The video is presented by Jesper Pedersen, who started with Qt back when Qt was widgets only and the version was 1.44, which gives him 21 years of experience with Qt. Since 2000 he has taught almost 100 Qt classes, ranging from Qt Widgets to QML. Heck, Jesper even taught a few classes on QTopia Core — Trolltech's initial attempt at creating a phone stack. Today Jesper holds a fancy business title, but that doesn't prevent him from coding both in his job and in his spare time.

About KDAB:

KDAB offers experienced software experts to help you deliver functional, high-performing and innovative softwae experts to help you deliver functional, high-performing and innovative software across embedded, mobile and desktop platforms for projects using C++, Qt, QML/Qt Quick, OpenGL, Qt 3D and more.  https://www.kdab.com/software-services

KDAB experts regularly take time out to deliver KDAB’s world class training, in-house or at open enrollment courses around the world. We are the market leaders for training in Qt, OpenGL and C++.

Contact us to find out more at training@kdab.com or visit our website: https://www.kdab.com/software-services/scheduled-training/

We are about 90 people, located all around the world. Our Head Office is in Sweden and we have other offices in Germany, France, the UK and the USA. https://www.kdab.com/about/contact/
Document Templates in Qt Creator - Part 2

It is possible to have your own document templates in Qt Creator, learn in these four videos how to set that up.
In this episode I'll show you how to add a new file (namely a .ui file) to the set of files generated, which among other things will teach us a bit more about how the macro system works.

The resulting template for these four episodes is in github. You can download it here https://github.com/KDAB/kdabtv

The video is presented by Jesper Pedersen, who started with Qt back when Qt was widgets only and the version was 1.44, which gives him 21 years of experience with Qt. Since 2000 he has taught almost 100 Qt classes, ranging from Qt Widgets to QML. Heck, Jesper even taught a few classes on QTopia Core — Trolltech's initial attempt at creating a phone stack. Today Jesper holds a fancy business title, but that doesn't prevent him from coding both in his job and in his spare time.

About KDAB:

KDAB offers experienced software experts to help you deliver functional, high-performing and innovative softwae experts to help you deliver functional, high-performing and innovative software across embedded, mobile and desktop platforms for projects using C++, Qt, QML/Qt Quick, OpenGL, Qt 3D and more. https://www.kdab.com/software-services

KDAB experts regularly take time out to deliver KDAB’s world class training, in-house or at open enrollment courses around the world. We are the market leaders for training in Qt, OpenGL and C++.

Contact us to find out more at training@kdab.com or visit our website: https://www.kdab.com/software-services/scheduled-training/

We are about 90 people, located all around the world. Our Head Office is in Sweden and we have other offices in Germany, France, the UK and the USA. https://www.kdab.com/about/contact/

10 4

YouTube Video UEw2Q0pZbjQwZ042Z2YtRy1vNnN5RndHcnRxM2tJdEVxSS45RTgxNDRBMzUwRjQ0MDhC

Document Templates in Qt Creator - Part 2

A nice feature of QListView and QTreeView is that the user can adapt the width of the columns using the mouse. A problem with that, however, is what to do if the column width is not wide enough to show all text. In this episode we will present an adapter that allows your model to provide multiple different strings the view can choose from.

The example code showcased in this video is available here: 
https://github.com/KDAB/kdabtv/tree/master/Qt-Widgets-and-more/ColumnHeaderLengthAdapter

All Qt Widgets and more videos:
https://www.youtube.com/playlist?list=PL6CJYn40gN6gf-G-o6syFwGrtq3kItEqI

About the host:
The video is presented by Jesper Pedersen, who started with Qt back when Qt was widgets only and the version was 1.44, which gives him 21 years of experience with Qt. Since 2000 he has taught almost 100 Qt classes, ranging from Qt Widgets to QML. Heck, Jesper even taught a few classes on QTopia Core — Trolltech's initial attempt at creating a phone stack. Today Jesper holds a fancy business title, but that doesn't prevent him from coding both in his job and in his spare time.

About KDAB:
KDAB offers experienced software experts to help you deliver functional, high-performing and innovative software across embedded, mobile and desktop platforms for projects using C++, Qt, QML/Qt Quick, OpenGL, Qt 3D and more.  https://www.kdab.com/software-services

KDAB experts regularly take time out to deliver KDAB’s world class training, in-house or at open enrollment courses around the world. We are the market leaders for training in Qt, OpenGL and C++.

Contact us to find out more at training@kdab.com or visit our website: https://www.kdab.com/software-services/scheduled-training/

We are about 90 people, located all around the world. Our Head Office is in Sweden and we have other offices in Germany, France, the UK and the USA. https://www.kdab.com/about/contact/
Adapting Column Content to Size

A nice feature of QListView and QTreeView is that the user can adapt the width of the columns using the mouse. A problem with that, however, is what to do if the column width is not wide enough to show all text. In this episode we will present an adapter that allows your model to provide multiple different string the view can choose from.

The example code showcased in this video is available here: https://github.com/KDAB/kdabtv

The video is presented by Jesper Pedersen, who started with Qt back when Qt was widgets only and the version was 1.44, which gives him 21 years of experience with Qt. Since 2000 he has taught almost 100 Qt classes, ranging from Qt Widgets to QML. Heck, Jesper even taught a few classes on QTopia Core — Trolltech's initial attempt at creating a phone stack. Today Jesper holds a fancy business title, but that doesn't prevent him from coding both in his job and in his spare time.

About KDAB:
KDAB offers experienced software experts to help you deliver functional, high-performing and innovative software across embedded, mobile and desktop platforms for projects using C++, Qt, QML/Qt Quick, OpenGL, Qt 3D and more. https://www.kdab.com/software-services

KDAB experts regularly take time out to deliver KDAB’s world class training, in-house or at open enrollment courses around the world. We are the market leaders for training in Qt, OpenGL and C++.

Contact us to find out more at training@kdab.com or visit our website: https://www.kdab.com/software-services/scheduled-training/

We are about 90 people, located all around the world. Our Head Office is in Sweden and we have other offices in Germany, France, the UK and the USA. https://www.kdab.com/about/contact/

31 1

YouTube Video UEw2Q0pZbjQwZ042Z2YtRy1vNnN5RndHcnRxM2tJdEVxSS5GM0Q3M0MzMzY5NTJFNTdE

Adapting Column Content to Size

In your code, you will likely find numerous places where you go from an enum to a QString and back. This could, for example, be code where you serialize your data.

The code might very well look like this:

    if (value == ExampleEnum::Foo)
        return "Foo";
    else if (value == ExampleEnum::Bar)
        return "Bar";
    ~~~

But there is a smarter way to do it, using Qt's introspection facilities. Watch here to learn that trick.

The example code showcased in this video is available here: 
https://github.com/KDAB/kdabtv/tree/master/Qt-Widgets-and-more/EnumConverter

All Qt Widgets and more videos:
https://www.youtube.com/playlist?list=PL6CJYn40gN6gf-G-o6syFwGrtq3kItEqI

About the host:
The video is presented by Jesper Pedersen, who started with Qt back when Qt was widgets only and the version was 1.44, which gives him 21 years of experience with Qt. Since 2000 he has taught almost 100 Qt classes, ranging from Qt Widgets to QML. Heck, Jesper even taught a few classes on QTopia Core — Trolltech's initial attempt at creating a phone stack. Today Jesper holds a fancy business title, but that doesn't prevent him from coding both in his job and in his spare time.

About KDAB:
KDAB offers experienced software experts to help you deliver functional, high-performing and innovative software across embedded, mobile and desktop platforms for projects using C++, Qt, QML/Qt Quick, OpenGL, Qt 3D and more.  https://www.kdab.com/software-services

KDAB experts regularly take time out to deliver KDAB’s world class training, in-house or at open enrollment courses around the world. We are the market leaders for training in Qt, OpenGL and C++.

Contact us to find out more at training@kdab.com or visit our website: https://www.kdab.com/software-services/scheduled-training/

We are about 90 people, located all around the world. Our Head Office is in Sweden and we have other offices in Germany, France, the UK and the USA. https://www.kdab.com/about/contact/
Converting Enums to and from Strings

In your code you will likely find numerous places where you go from an enum to a QString and back. This could for example be code where you serialize your data.

The code might very well look like this

if (value == ExampleEnum::Foo)
return "Foo";
else if (value == ExampleEnum::Bar)
return "Bar";
~~~

But there is a smarter way to do it using Qt's introspection facilities. Watch here to learn that trick.

The example code showcased in this video is available here: https://github.com/KDAB/kdabtv

The video is presented by Jesper Pedersen, who started with Qt back when Qt was widgets only and the version was 1.44, which gives him 21 years of experience with Qt. Since 2000 he has taught almost 100 Qt classes, ranging from Qt Widgets to QML. Heck, Jesper even taught a few classes on QTopia Core — Trolltech's initial attempt at creating a phone stack. Today Jesper holds a fancy business title, but that doesn't prevent him from coding both in his job and in his spare time.

About KDAB:
KDAB offers experienced software experts to help you deliver functional, high-performing and innovative software across embedded, mobile and desktop platforms for projects using C++, Qt, QML/Qt Quick, OpenGL, Qt 3D and more. https://www.kdab.com/software-services

KDAB experts regularly take time out to deliver KDAB’s world class training, in-house or at open enrollment courses around the world. We are the market leaders for training in Qt, OpenGL and C++.

Contact us to find out more at training@kdab.com or visit our website: https://www.kdab.com/software-services/scheduled-training/

We are about 90 people, located all around the world. Our Head Office is in Sweden and we have other offices in Germany, France, the UK and the USA. https://www.kdab.com/about/contact/

61 10

YouTube Video UEw2Q0pZbjQwZ042Z2YtRy1vNnN5RndHcnRxM2tJdEVxSS4zRjM0MkVCRTg0MkYyQTM0

Converting Enums to and from Strings

In this first episode on developing plugins for Qt Designer, we will discuss the widget promotion feature and its shortcomings compared to plugins.
This is the first video out of 6 on this topic. So, stay tuned!

The example code showcased in this video is available here: https://github.com/KDAB/kdabtv/tree/master/Qt-Widgets-and-more/WidgetPromotion

All Qt Designer Plugins videos:
https://www.youtube.com/playlist?list=PL6CJYn40gN6iNg0nIYH4QLhYkfs5PslbA

All Qt Widgets and more videos:
https://www.youtube.com/playlist?list=PL6CJYn40gN6gf-G-o6syFwGrtq3kItEqI

About the host:
The video is presented by Jesper Pedersen, who started with Qt back when Qt was widgets only and the version was 1.44, which gives him 21 years of experience with Qt. Since 2000 he has taught almost 100 Qt classes, ranging from Qt Widgets to QML. Heck, Jesper even taught a few classes on QTopia Core — Trolltech's initial attempt at creating a phone stack. Today Jesper holds a fancy business title, but that doesn't prevent him from coding both in his job and in his spare time.

About KDAB:
KDAB offers experienced software experts to help you deliver functional, high-performing and innovative software across embedded, mobile and desktop platforms for projects using C++, Qt, QML/Qt Quick, OpenGL, Qt 3D and more.  https://www.kdab.com/software-services

KDAB experts regularly take time out to deliver KDAB’s world class training, in-house or at open enrollment courses around the world. We are the market leaders for training in Qt, OpenGL and C++.

Contact us to find out more at training@kdab.com or visit our website: https://www.kdab.com/software-services/scheduled-training/

We are about 90 people, located all around the world. Our Head Office is in Sweden and we have other offices in Germany, France, the UK and the USA. https://www.kdab.com/about/contact/
Qt Designer Plugins (Part 1) - Widgets Promotion

In this first episode on developing plugins for Qt Designer, we will discuss the widget promotion feature and discuss its shortcoming compared to plugins.
This is the first video out of 6 on this topic so stay tuned!

The example code showcased in this video is available here: https://github.com/KDAB/kdabtv

The video is presented by Jesper Pedersen, who started with Qt back when Qt was widgets only and the version was 1.44, which gives him 21 years of experience with Qt. Since 2000 he has taught almost 100 Qt classes, ranging from Qt Widgets to QML. Heck, Jesper even taught a few classes on QTopia Core — Trolltech's initial attempt at creating a phone stack. Today Jesper holds a fancy business title, but that doesn't prevent him from coding both in his job and in his spare time.

About KDAB:
KDAB offers experienced software experts to help you deliver functional, high-performing and innovative software across embedded, mobile and desktop platforms for projects using C++, Qt, QML/Qt Quick, OpenGL, Qt 3D and more. https://www.kdab.com/software-services

KDAB experts regularly take time out to deliver KDAB’s world class training, in-house or at open enrollment courses around the world. We are the market leaders for training in Qt, OpenGL and C++.

Contact us to find out more at training@kdab.com or visit our website: https://www.kdab.com/software-services/scheduled-training/

We are about 90 people, located all around the world. Our Head Office is in Sweden and we have other offices in Germany, France, the UK and the USA. https://www.kdab.com/about/contact/

82 12

YouTube Video UEw2Q0pZbjQwZ042Z2YtRy1vNnN5RndHcnRxM2tJdEVxSS45NzUwQkI1M0UxNThBMkU0

Qt Designer Plugins (Part 1) - Widgets Promotion

Before you create a plugin, your classes may be configured using constructors like:

class Wishes {
public:
  Wishes(bool isExclusive, const QColor& color, QWidget* parent);
  ...
}

But how do you handle these parameters if your constructors can't take anything but the parent pointer?

This episode will discuss a few different possible solutions.

This is the second video out of 6 on this topic. So stay tuned!

The example code showcased in this video is available here: 
https://github.com/KDAB/kdabtv/tree/master/Qt-Widgets-and-more/WidgetInitialization

All Qt Designer Plugins videos:
https://www.youtube.com/playlist?list=PL6CJYn40gN6iNg0nIYH4QLhYkfs5PslbA

All Qt Widgets and more videos:
https://www.youtube.com/playlist?list=PL6CJYn40gN6gf-G-o6syFwGrtq3kItEqI

About the host:
The video is presented by Jesper Pedersen, who started with Qt back when Qt was widgets only and the version was 1.44, which gives him 21 years of experience with Qt. Since 2000 he has taught almost 100 Qt classes, ranging from Qt Widgets to QML. Heck, Jesper even taught a few classes on QTopia Core — Trolltech's initial attempt at creating a phone stack. Today Jesper holds a fancy business title, but that doesn't prevent him from coding both in his job and in his spare time.

About KDAB:
KDAB offers experienced software experts to help you deliver functional, high-performing and innovative software across embedded, mobile and desktop platforms for projects using C++, Qt, QML/Qt Quick, OpenGL, Qt 3D and more.  https://www.kdab.com/software-services

KDAB experts regularly take time out to deliver KDAB’s world class training, in-house or at open enrollment courses around the world. We are the market leaders for training in Qt, OpenGL and C++.

Contact us to find out more at training@kdab.com or visit our website: https://www.kdab.com/software-services/scheduled-training/

We are about 90 people, located all around the world. Our Head Office is in Sweden and we have other offices in Germany, France, the UK and the USA. https://www.kdab.com/about/contact/
Qt Designer Plugins (Part 2) - Initializing Classes when Using Qt Designer

Before you create a plugin, your classes may be configured using constructors, like:

class Wishes {
public:
Wishes(bool isExclusive, const QColor& color, QWidget* parent);
...
}

But how do you handle these parameters if your constructors can't take anything but the parent pointer?

This episode will discuss a few different possible solutions.

This is the second video out of 6 on this topic so stay tuned!

The example code showcased in this video is available here: https://github.com/KDAB/kdabtv

The video is presented by Jesper Pedersen, who started with Qt back when Qt was widgets only and the version was 1.44, which gives him 21 years of experience with Qt. Since 2000 he has taught almost 100 Qt classes, ranging from Qt Widgets to QML. Heck, Jesper even taught a few classes on QTopia Core — Trolltech's initial attempt at creating a phone stack. Today Jesper holds a fancy business title, but that doesn't prevent him from coding both in his job and in his spare time.

About KDAB:
KDAB offers experienced software experts to help you deliver functional, high-performing and innovative software across embedded, mobile and desktop platforms for projects using C++, Qt, QML/Qt Quick, OpenGL, Qt 3D and more. https://www.kdab.com/software-services

KDAB experts regularly take time out to deliver KDAB’s world class training, in-house or at open enrollment courses around the world. We are the market leaders for training in Qt, OpenGL and C++.

Contact us to find out more at training@kdab.com or visit our website: https://www.kdab.com/software-services/scheduled-training/

We are about 90 people, located all around the world. Our Head Office is in Sweden and we have other offices in Germany, France, the UK and the USA. https://www.kdab.com/about/contact/

33 1

YouTube Video UEw2Q0pZbjQwZ042Z2YtRy1vNnN5RndHcnRxM2tJdEVxSS5DNzE1RjZEMUZCMjA0RDBB

Qt Designer Plugins (Part 2) - Initializing Classes when Using Qt Designer

Categories: C++ / KDAB Blogs / KDAB on Qt

22 thoughts on “Qt Input Method – Virtual Keyboard”

  1. I think you article is very interesting, and also important for me. I have heavy problems to be able to use a im_module inside Linux Mint for Qt5 programs. You use Qt5 for compile your program ? I tried it, and later i use a test program compiled with Qt5, with only one QLineEdit at center of a QWidget, but without success. A keyboard not appear after run “server” , export and set to vkim and then execute my program with QLineEdit. Have you some idea ? Have used also Qt ? Thanks for any help. Daniel

  2. Hi Tobias (sprichst Du Deutsch ?).
    Thanks for your quick answer. What i do now is from a clean environment, install Qt (from VirtualBox) and see what will happen, because i have too many directories. Previous i use a release version and also check QT_PLUGIN_PATH, .. but without success. I am writing already from a virtual Ubuntu. Daniel

  3. I tell you about the exactly steps what i do :
    1) install Ubuntu
    2) install Qt on /home/daniel/Qt
    3) download virtual-keyboard-demo
    4) install “build-essential” and “libgl1-mesa-dev”
    5) now i can compile “plugin” and “server” from Qt Creator, which i do with release-mode
    6) i check, plugin is released on folder /home/daniel/Qt/5.5/gcc_64/plugins/platforminputcontexts/
    7) start “./server”
    8) set environment variables. I see at begin, many environment variables are not set except QT_IM_MODULE which is set to ibus. I set :
    export QTDIR=/home/daniel/Qt/5.5/gcc_64/
    export QT_PLUGIN_PATH=$QTDIR”plugins” (a echo return /home/daniel/Qt/5.5/gcc_64/plugins)
    export QT_IM_MODULE=vkim (“echo $QT_IM_MODULE” return “vkim”)
    9) i start designer with :
    $QTDIR”bin/designer”

    Something is wrong, if i click on a QLineEdit, a keyboard not appear, i only can see it with
    $QTDIR”bin/qdbusviewer” and playing with :
    – click on “com.kdab.inputmethod”
    – click on “Virtualkeyboard” at right
    – local.server.Keyboard
    – double click at Method:showKeyboard (keyboard appear)
    – Signal:keyClicked
    and every signal is received pushing buttons of this keyboard

    1. Tobias Koenig

      Hej Daniel,

      you have been right, the code didn’t work with latest Qt 5.5, because the IID for the plugin meta data has changed from “org.qt-project.Qt.QPlatformInputContextFactoryInterface” to “org.qt-project.Qt.QPlatformInputContextFactoryInterface.5.1”.

      I have fixed the code in the repository now, instead of hard-coding the string literal, it uses the QPlatformInputContextFactoryInterface_iid define now.

      Thank you very much for spotting it! 🙂

  4. Hi Tobias.
    I am very happy, because now is working. This will give me hope to make working also “gcin” input method, which we always use.
    Very much thanks for your help.

    Daniel

  5. Thanks for the interesting article. I am in the process of converting a Qt4 application to run on Qt5 and now have everything working except the On-Screen-Keyboard. As our software runs on proprietary devices and is the only running application that has any user interaction via the screen, I am interested in the in-process approach which you say in your introduction “… is very easy to implement”. I’m struggling to find documentation anywhere on how to do this and wondered if you could point me at any or explain how your implementation would be adapted? I already have the OSK from my Qt4 app so just being able to hook it up would be really good – especially as I was given 1 day to do the whole migration and I’ve already taken 2 (which, all things considered is not too bad considering it has over 400,000 lines of code) 🙂 The OSK is now the only stumbling block. Thanks again.

    1. Tobias Koenig

      Hej Simon,

      the in-process OSK can be implemented by just creating corresponding QKeyEvent objects, whenever the user presses/releases on one of the OSK button, and deliver them to the current focus object of the application, e.g. QGuiApplication::sendEvent(QGuiApplication::focusObject(), event). You just have to make sure that clicking the button on the OSK won’t let it take the focus (see how it is done on the external OSK in the example in the git repo).

      1. Thanks Tobias – I hope you won’t mind if I ask one more question: In my Qt4 application, after instantiating my own class which inherited from QInputContext all I had to do was call qApp->setInputContext and this ensured that when I touched a UI input element my OSK would pop-up. Is there something similar I can do in Qt5 with my QPlatformInputContext derived class or do I need to hook all of that up manually too?
        Thanks again.

        1. Tobias Koenig

          Hej Simon,

          the QGuiApplication::setInputContext() method has been removed in Qt5. To use a custom input method, you have to implement and install your own input method plugin and make the application using it by setting the QT_IM_MODULE environment variable.

  6. Is there any way you can show how to do the virtual keyboard by doing the in process approach? I am confused how it would be different than the out of process approach.

    1. Tobias Koenig

      Hej Christina,

      for the in-process version, you’d simply put the virtual keyboard widget into the main application and let it communicate directly with the QVkImPlatformInputContext, so the separate server process and dbus communication is left out.

  7. Hello

    It’s very valuable information for me. However I have an issue to build ‘plugin’ project.
    When I try ‘qmake’ with Qt 5.7, it has totally no problem, but with Qt 5.8 I always get:
    “Project ERROR: Could not find feature reduce_exports”.

    From some forums in the internet, I now know it was caused by “load(qt_plugin)”, but I don’t know how to fix it.

    Do you have any idea on it?

    Thank you.

    1. Tobias Koenig

      Hej,

      I just pushed a fix to the git repository, which fixes compilation with Qt 5.8, please re-pull.

  8. hi:
    The virtualkeyboard run well,but When I transplat it to the platform of arm ,it has a vital problem as follows:
    QObject::connect: No such signal QDBusAbstractInterface::keyClicked(QString)
    Unable to register at DBus
    Aborted

    1. Tobias Koenig

      Hej,

      the error message says it all: ‘Unable to register at DBus’, so your system seems to miss a running DBus daemon where the virtual keyboard could connect to.

  9. Hi Tobias
    Thanks so much for a very informative post.
    I was able to make it work “in-process” by putting the keyboard class in the plug-in and it’s been working so far. Is there any problem with instantiating widgets in a plug-in?

    Thanks
    Steve

    1. Tobias Koenig

      Hej Steve,

      instantiating a widget from a plug-in is perfectly fine (that’s how QtCreator creates most of its UI for example), just make sure that do you not unload the plugin as long a such a widget instance is still around.

  10. Hi, nice article. Thanks for sharing.

    My only issue with the way you build the keyboard using QGridLayout is that it is fairly limiting to mimic a real keyboard virtually. This is because hardware keyboards do not seem to map well into a QGridLayout. They seem to be more freestyle with alignments.

    Do you feel that setGeometry on the QPushButtons is a more practical way to go? That is how I implemented it at least and that resembles a real keyboard (or even other virtual keyboards) closer.

    1. Tobias Koenig

      Hej Laszlo,

      the article concentrated more about what happens behind the scenes, not so much about making a pretty UI 🙂 So sure, in an actual product software the keyboard UI should adapt to real keyboard layouts and support switching between various ones.

Leave a Reply

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