-
Notifications
You must be signed in to change notification settings - Fork 748
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
QAbstractItemModel #24
Comments
It's currently not possible, because it's an abstract class and I need to implement all missing pure virtual functions first. So, it will take some time. |
No prob. I will use the widget versions of Tree and Table. Thanks! |
It's implemented now c0571ee |
Oh wow. You are working faster than me! I will try to test this soon. Thanks! |
I just updated to latest version. QTableWidget seems to be broken: package main
import (
"os"
"github.com/therecipe/qt/widgets"
)
func main() {
widgets.NewQApplication(len(os.Args), os.Args)
// Main Window
var window = widgets.NewQMainWindow(nil, 0)
// Main Widget
mw := widgets.NewQTableWidget2(12, 3, nil)
// Set Central Widget
window.SetCentralWidget(mw)
// Run App
widgets.QApplication_SetStyle2("fusion")
window.ShowMaximized()
widgets.QApplication_Exec()
} |
Maybe it is that I am using 1.5 instead of 1.6? I will update and check. Thanks. |
That didn't seem to help. Still broken. Notice something I think is funny - widgets takes 0 sec and sql takes 13min:
|
Hey Yes, some functions were missing and therefore QTableWidget didn't work. Also the QTableWidget should work now: 5fb71be |
Thanks! |
You are welcome. |
Hi :) First - very impressed with the 5.6 upgrade which didn't break any of my code! Thank you! Finally getting around to testing QAbstractItemModel : package main
import (
"os"
"github.com/therecipe/qt/core"
"github.com/therecipe/qt/gui"
"github.com/therecipe/qt/widgets"
)
type delegate struct {
*widgets.QStyledItemDelegate
}
func main() {
widgets.NewQApplication(len(os.Args), os.Args)
// Main Window
var window = widgets.NewQMainWindow(nil, 0)
window.SetWindowTitle("--")
// Main Widget
view := widgets.NewQTableView(nil)
model := gui.NewQStandardItemModel2(2, 2, nil)
view.SetModel(model)
delegate := NewDelegate()
view.SetItemDelegate(delegate)
// Set Central Widget
window.SetCentralWidget(view)
// Run App
widgets.QApplication_SetStyle2("fusion")
window.ShowMaximized()
widgets.QApplication_Exec()
}
func NewDelegate() *widgets.QStyledItemDelegate {
item := widgets.NewQStyledItemDelegate(nil)
item.ConnectCreateEditor(createEditor)
item.ConnectSetEditorData(setEditorData)
item.ConnectSetModelData(setModelData)
item.ConnectUpdateEditorGeometry(updateEditorGeometry)
}
func (d *delegate) createEditor(parent widgets.QWidget_ITF, option widgets.QStyleOptionViewItem_ITF, index core.QModelIndex_ITF) *widgets.QWidget {
editor := widgets.NewQSpinBox(nil)
editor.SetMinimum(0)
editor.SetMaximum(100)
return editor
}
func (d *delegate) setEditorData(editor widgets.QWidget_ITF, index core.QModelIndex_ITF) {
value := index.Model().Data(index, 2).ToInt() // 2 = Qt::EditRole
editor.SetValue(value)
}
func (d *delegate) setModelData(editor widgets.QWidget_ITF, model core.QAbstractItemModel_ITF, index core.QModelIndex_ITF) {
editor.InterpretText()
value := editor.Value()
model.SetData(index, value, 2) // 2 = Qt::EditRole
}
func (d *delegate) updateEditorGeometry(editor widgets.QWidget_ITF, option widgets.QStyleOptionViewItem_ITF, index core.QModelIndex_ITF) {
editor.SetGeometry(option.Rect)
} I get a lot of errors. Following from this example: http://www.bogotobogo.com/Qt/Qt5_QTableView_QItemDelegate_ModelView_MVC.php Could you take a look when you get a chance? Thanks! |
Hey Thank you :) The errors you saw, are from a bug in the type Delegate struct {
widgets.QStyledItemDelegate //don't use *pointers or it won't work
} The The If you don't want to use the type Delegate struct {
item widgets.QStyledItemDelegate
} (just don't use Qt classes in anonymous fields) Sorry, this got a little longer than I expected. I got your QAbstractItemModel example working with this commit 9476e3f: package main
import (
"os"
"github.com/therecipe/qt/core"
"github.com/therecipe/qt/gui"
"github.com/therecipe/qt/widgets"
)
type Delegate struct {
widgets.QStyledItemDelegate //don't use *pointers or it won't work
}
func main() {
widgets.NewQApplication(len(os.Args), os.Args)
// Main Window
var window = widgets.NewQMainWindow(nil, 0)
window.SetWindowTitle("--")
// Main Widget
view := widgets.NewQTableView(nil)
model := gui.NewQStandardItemModel2(2, 2, nil)
view.SetModel(model)
delegate := InitDelegate()
view.SetItemDelegate(delegate)
// Set Central Widget
window.SetCentralWidget(view)
// Run App
widgets.QApplication_SetStyle2("fusion")
window.Show()
widgets.QApplication_Exec()
}
func InitDelegate() *Delegate {
item := NewDelegate(nil) //will be generated in moc.go
item.ConnectCreateEditor(createEditor)
item.ConnectSetEditorData(setEditorData)
item.ConnectSetModelData(setModelData)
item.ConnectUpdateEditorGeometry(updateEditorGeometry)
return item
}
func createEditor(parent *widgets.QWidget, option *widgets.QStyleOptionViewItem, index *core.QModelIndex) *widgets.QWidget {
editor := widgets.NewQSpinBox(parent)
editor.SetMinimum(0)
editor.SetMaximum(100)
return editor.QWidget_PTR()
}
func setEditorData(editor *widgets.QWidget, index *core.QModelIndex) {
value := index.Model().Data(index, int(core.Qt__EditRole)).ToInt(true)
spinbox := widgets.NewQSpinBoxFromPointer(editor.Pointer()) //like static_cast
spinbox.SetValue(value)
}
func setModelData(editor *widgets.QWidget, model *core.QAbstractItemModel, index *core.QModelIndex) {
spinbox := widgets.NewQSpinBoxFromPointer(editor.Pointer()) //like static_cast
spinbox.InterpretText()
value := spinbox.Value()
model.SetData(index, core.NewQVariant7(value), int(core.Qt__EditRole))
}
func updateEditorGeometry(editor *widgets.QWidget, option *widgets.QStyleOptionViewItem, index *core.QModelIndex) {
editor.SetGeometry(option.Rect())
} |
It works :) Thanks!! |
Hi, I'm getting: argstable.go:25: undefined: NewDelegate package argstable
import (
"github.com/therecipe/qt/core"
"github.com/therecipe/qt/gui"
"github.com/therecipe/qt/widgets"
)
type Delegate struct {
widgets.QStyledItemDelegate //don't use *pointers or it won't work
}
func NewArgsTable() *widgets.QTableView {
view := widgets.NewQTableView(nil)
model := gui.NewQStandardItemModel2(2, 1, nil)
view.SetModel(model)
delegate := InitDelegate()
view.SetItemDelegate(delegate)
return view
}
func InitDelegate() *Delegate {
item := NewDelegate(nil) //will be generated in moc.go
item.ConnectCreateEditor(createEditor)
item.ConnectSetEditorData(setEditorData)
item.ConnectSetModelData(setModelData)
item.ConnectUpdateEditorGeometry(updateEditorGeometry)
return item
}
func createEditor(parent *widgets.QWidget, option *widgets.QStyleOptionViewItem, index *core.QModelIndex) *widgets.QWidget {
editor := widgets.NewQLineEdit(parent)
// editor.SetMinimum(0)
// editor.SetMaximum(100)
return editor.QWidget_PTR()
}
func setEditorData(editor *widgets.QWidget, index *core.QModelIndex) {
value := index.Model().Data(index, int(core.Qt__EditRole)).ToString() //ToInt(true)
lineedit := widgets.NewQLineEditFromPointer(editor.Pointer()) //like static_cast
lineedit.SetText(value)
}
func setModelData(editor *widgets.QWidget, model *core.QAbstractItemModel, index *core.QModelIndex) {
lineedit := widgets.NewQLineEditFromPointer(editor.Pointer()) //like static_cast
text := lineedit.Text()
model.SetData(index, core.NewQVariant14(text), int(core.Qt__EditRole))
// lineedit.InterpretText()
// value := lineedit.Value()
// model.SetData(index, core.NewQVariant7(value), int(core.Qt__EditRole))
}
func updateEditorGeometry(editor *widgets.QWidget, option *widgets.QStyleOptionViewItem, index *core.QModelIndex) {
editor.SetGeometry(option.Rect())
} |
Hey Currently you need to cd into the folder (argstable) and run I will fix this and post here, once it's done. |
It should be fixed now a6a0643 |
That works. Thanks! |
Is this possible or should I just use the Tree/Table Widget?
The text was updated successfully, but these errors were encountered: