From 7533371ccfdaeafd4dcd989b46c0daf962a72a62 Mon Sep 17 00:00:00 2001 From: velorums Date: Wed, 2 Apr 2025 20:28:13 +0200 Subject: [PATCH] Add Qt 6 Qml example --- examples/helloqml6/main.go | 43 +++++++++++++++++++++++++++++++++++++ examples/helloqml6/main.qml | 20 +++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 examples/helloqml6/main.go create mode 100644 examples/helloqml6/main.qml diff --git a/examples/helloqml6/main.go b/examples/helloqml6/main.go new file mode 100644 index 00000000..f644a6bf --- /dev/null +++ b/examples/helloqml6/main.go @@ -0,0 +1,43 @@ +package main + +import ( + "fmt" + "os" + + qt "github.com/mappu/miqt/qt6" + "github.com/mappu/miqt/qt6/qml" +) + +func main() { + qt.NewQApplication(os.Args) + + engine := qml.NewQQmlApplicationEngine() + + url := qt.QUrl_FromLocalFile("main.qml") + + model := qt.NewQAbstractListModel() + + model.OnRowCount(func(parent *qt.QModelIndex) int { + return 1000 + }) + + model.OnData(func(idx *qt.QModelIndex, role int) *qt.QVariant { + if !idx.IsValid() { + return qt.NewQVariant() + } + + switch qt.ItemDataRole(role) { + case qt.DisplayRole: + return qt.NewQVariant14(fmt.Sprintf("this is row %d", idx.Row())) + + default: + return qt.NewQVariant() + } + }) + + engine.RootContext().SetContextProperty("myModel", model.QObject) + + engine.Load(url); + + qt.QApplication_Exec() +} diff --git a/examples/helloqml6/main.qml b/examples/helloqml6/main.qml new file mode 100644 index 00000000..f2ee2192 --- /dev/null +++ b/examples/helloqml6/main.qml @@ -0,0 +1,20 @@ +import QtQuick +import QtQuick.Controls +import QtQuick.Window + +Window { + width: 640 + height: 480 + visible: true + + title: "Hello World" + + ListView { + anchors.fill: parent + model: myModel + delegate: Row { + spacing: 10 + Text { text: display } + } + } +}