mirror of
https://github.com/mappu/miqt.git
synced 2025-04-19 03:40:23 +00:00
Add Qt 6 Qml example
This commit is contained in:
parent
f7963788ee
commit
7533371ccf
43
examples/helloqml6/main.go
Normal file
43
examples/helloqml6/main.go
Normal file
@ -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()
|
||||||
|
}
|
20
examples/helloqml6/main.qml
Normal file
20
examples/helloqml6/main.qml
Normal file
@ -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 }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user