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() +}