diff options
Diffstat (limited to 'examples/quick/tableview/pixelator')
5 files changed, 11 insertions, 11 deletions
diff --git a/examples/quick/tableview/pixelator/doc/src/pixelator.qdoc b/examples/quick/tableview/pixelator/doc/src/pixelator.qdoc index 9e199a5347..88b28769cd 100644 --- a/examples/quick/tableview/pixelator/doc/src/pixelator.qdoc +++ b/examples/quick/tableview/pixelator/doc/src/pixelator.qdoc @@ -42,6 +42,7 @@ TableView. We use the \l{The Property System}{Qt Property System} and a source property as \c QString to set the path of the image. + We also add the QML_ELEMENT macro to expose the model to QML. \snippet tableview/pixelator/imagemodel.cpp setsource @@ -59,11 +60,6 @@ When we call this function with the display role, we return the pixel's gray value. - \snippet tableview/pixelator/main.cpp registertype - - We need to register our model in the QML type system to be able to use it - from the QML side. - \snippet tableview/pixelator/main.qml pixelcomponent Each pixel in the \c TableView is displayed via a delegate component. diff --git a/examples/quick/tableview/pixelator/imagemodel.h b/examples/quick/tableview/pixelator/imagemodel.h index bf0ec90da4..de8ad7cd8d 100644 --- a/examples/quick/tableview/pixelator/imagemodel.h +++ b/examples/quick/tableview/pixelator/imagemodel.h @@ -53,12 +53,14 @@ #include <QAbstractTableModel> #include <QImage> +#include <QtQml/qqml.h> //! [model] class ImageModel : public QAbstractTableModel { Q_OBJECT Q_PROPERTY(QString source READ source WRITE setSource NOTIFY sourceChanged) + QML_ELEMENT public: ImageModel(QObject *parent = nullptr); diff --git a/examples/quick/tableview/pixelator/main.cpp b/examples/quick/tableview/pixelator/main.cpp index c57039556a..c07f43dc27 100644 --- a/examples/quick/tableview/pixelator/main.cpp +++ b/examples/quick/tableview/pixelator/main.cpp @@ -59,10 +59,6 @@ int main(int argc, char *argv[]) QQmlApplicationEngine engine; - //! [registertype] - qmlRegisterType<ImageModel>("ImageModel", 1, 0, "ImageModel"); - //! [registertype] - engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); if (engine.rootObjects().isEmpty()) return -1; diff --git a/examples/quick/tableview/pixelator/main.qml b/examples/quick/tableview/pixelator/main.qml index 38a25f439f..a5edefae90 100644 --- a/examples/quick/tableview/pixelator/main.qml +++ b/examples/quick/tableview/pixelator/main.qml @@ -65,7 +65,9 @@ Window { id: pixelDelegate Item { - readonly property real gray: model.display / 255.0 + required property real display + + readonly property real gray: display / 255.0 readonly property real size: 16 implicitWidth: size @@ -77,7 +79,7 @@ Window { id: rect anchors.centerIn: parent color: "#09102b" - radius: size - gray * size + radius: parent.size - parent.gray * parent.size implicitWidth: radius implicitHeight: radius //! [rectshape] diff --git a/examples/quick/tableview/pixelator/pixelator.pro b/examples/quick/tableview/pixelator/pixelator.pro index 6c863cb304..f27303b56b 100644 --- a/examples/quick/tableview/pixelator/pixelator.pro +++ b/examples/quick/tableview/pixelator/pixelator.pro @@ -5,6 +5,10 @@ HEADERS += imagemodel.h SOURCES += main.cpp \ imagemodel.cpp +CONFIG += qmltypes +QML_IMPORT_NAME = ImageModel +QML_IMPORT_MAJOR_VERSION = 1 + RESOURCES += qt.png main.qml target.path = $$[QT_INSTALL_EXAMPLES]/quick/tableview/pixelator |