Add Slot In Qt Designer

In Part 1, we constructed our application framework and layout using Qt Designer. Part 2 of this series explored the custom subclass creation that was necessary to add custom logic to our application. In this installment, we will look at adding multiple figures to our application and including their names in the list widget.

Add slot in qt designer download

The principle of using placeholders in Qt Designer is quite straightforward — Create a UI as normal in Qt Designer. Add a placeholder widget to represent the custom widget you're adding. Tell Qt to replace your placeholder with your actual widget when building the UI. In Qt this final step is referred to as promoting (as in promoting a base. Add a protected slot named init. This slot will automatically be added in the source window. This is one of two special slots added by Qt Designer to avoid the old (Qt version 2.x) approach when it was necessary to sub-class each dialog to add a constructor.

One of the most useful basic features of Qt is the support for buddy widgets. A buddy widget accepts the input focus on behalf of a QLabel when the user types the label's shortcut key combination. The buddy concept is also used in Qt's model/view framework.

Linking Labels to Buddy Widgets

To enter buddy editing mode, open the Edit menu and select Edit Buddies. This mode presents the widgets on the form in a similar way to signals and slots editing mode but in this mode, connections must start at label widgets. Ideally, you should connect each label widget that provides a shortcut with a suitable input widget, such as a QLineEdit.

Making Buddies

To define a buddy widget for a label, click on the label, drag the connection to another widget on the form, and release the mouse button. The connection shown indicates how input focus is passed to the buddy widget. You can use the form preview to test the connections between each label and its buddy.

Add Slot In Qt Designer App

Add slot in qt designer free

Add Slot In Qt Designer Free

Removing Buddy Connections

Add Slot In Qt Designer Download

Only one buddy widget can be defined for each label. To change the buddy used, it is necessary to delete any existing buddy connection before you create a new one.

Add Slot In Qt Designer

Connections between labels and their buddy widgets can be deleted in the same way as signal-slot connections in signals and slots editing mode: Select the buddy connection by clicking on it and press the Delete key. This operation does not modify either the label or its buddy in any way.

© 2020 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.