qskinny/doc/tutorials/08-qskinny-and-qml.md

1.6 KiB
Raw Blame History

Tutorials

QSkinny - Using QSkinny and QML

Combining QSkinny and QML is possible: Since both QML elements and QSkinny controls derive from QQuickItem, they can be combined and arranged in a common app. The https://github.com/uwerat/qskinny/tree/master/examples/buttons[QSkinny buttons example] shows how QSkinny controls can be used from QML.

When using a QSkinny control, all the methods exposed as either properties, slots or invokables can be used in QML. For example, the QSkinny control QskLinearBox defines the following properties:

CMakeLists.txt

target_link_libraries(myapp PRIVATE 
    ...
    Qsk::QmlExport)
...
class QSK_EXPORT QskLinearBox : public QskIndexedLayoutBox
{
    Q_PROPERTY( Qt::Orientation orientation READ orientation WRITE setOrientation NOTIFY orientationChanged FINAL )
    Q_PROPERTY( qreal spacing READ spacing WRITE setSpacing RESET resetSpacing NOTIFY spacingChanged FINAL )
    ...
};

The QskLinearBox class is registered to QML as Qsk.LinearBox via Qts qmlRegisterType, so the exposed properties orientation and spacing can be used like this:

Qsk.LinearBox
{
    orientation: Qt.Horizontal
    spacing: 10

    // here define elements inside the box
    ...
}

The full Buttons example is depicted below.

The buttons example shows how to mix QSkinny and QML

Buttons example

For more information on using C++ classes from QML, see the article about exposing attributes of {cpp} types to QML in the Qt documentation.