From a0e56bf7c208452d9ecfbbd6fe05915f0da19d10 Mon Sep 17 00:00:00 2001 From: mappu Date: Sat, 23 Nov 2024 20:02:41 +1300 Subject: [PATCH] examples/modelview: initial commit --- .gitignore | 1 + examples/modelview/main.go | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 examples/modelview/main.go diff --git a/.gitignore b/.gitignore index 2e87edd7..9582fb36 100644 --- a/.gitignore +++ b/.gitignore @@ -28,6 +28,7 @@ examples/windowsmanifest/windowsmanifest examples/uidesigner/uidesigner examples/trivialwizard6/trivialwizard6 examples/subclass/subclass +examples/modelview/modelview examples/libraries/extras-scintillaedit/extras-scintillaedit examples/libraries/qt-multimedia/qt-multimedia examples/libraries/qt-network/qt-network diff --git a/examples/modelview/main.go b/examples/modelview/main.go new file mode 100644 index 00000000..557f3493 --- /dev/null +++ b/examples/modelview/main.go @@ -0,0 +1,38 @@ +package main + +import ( + "fmt" + "os" + + "github.com/mappu/miqt/qt" +) + +func main() { + qt.NewQApplication(os.Args) + + 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() + } + }) + + v := qt.NewQListView2() + v.SetModel(model.QAbstractItemModel) + v.Show() + + qt.QApplication_Exec() +}