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

56 lines
1.6 KiB
Markdown
Raw Normal View History

2024-11-29 15:18:09 +00:00
# Tutorials {#tutorials}
2024-11-29 15:18:09 +00:00
## 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:
2024-11-29 15:18:09 +00:00
**CMakeLists.txt**
```cmake
target_link_libraries(myapp PRIVATE
...
Qsk::QmlExport)
...
2024-11-29 15:18:09 +00:00
```
2024-11-29 15:18:09 +00:00
```cpp
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 )
...
};
2024-11-29 15:18:09 +00:00
```
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:
2024-11-29 15:18:09 +00:00
```
Qsk.LinearBox
{
orientation: Qt.Horizontal
spacing: 10
// here define elements inside the box
...
}
2024-11-29 15:18:09 +00:00
```
The full Buttons example is depicted below.
2024-11-29 15:18:09 +00:00
**The buttons example shows how to mix QSkinny and QML**
![Buttons example](/doc/tutorials/images/buttons-example.png)
For more information on using C++ classes from QML, see the article about exposing attributes of {cpp} types to QML in the
2024-11-29 15:18:09 +00:00
[Qt documentation](https://doc.qt.io/qt-5/qtqml-cppintegration-exposecppattributes.html).