[PyQt] Problem getting QItemDelegate to work
davidh at ilm.com
Fri Apr 25 18:16:30 BST 2008
Didn't get any response yesterday...wondering if I didn't give enough
Even a working example in python of a table or list view using
QItemDelegate subclasses to display persistent editors would be enough
to get me going...I just can't seem to get it to work right.
David Hirschfield wrote:
> I have a simple test app which displays a QTableWidget with a custom
> QItemDelegate to display the items as buttons, checkboxes and comboboxes.
> The widgets are supposed to be editable at all times, so I use:
> self.widgetTable.setItem(row, i, tableItem)
> to add the item and make the editor always visible and ready for
> I'm not having any trouble setting up the table and having my rows
> display properly with the widgets ready for interaction. The problem
> comes when I interact with the editor widgets.
> My QItemDelegate subclass, called WidgetDelegate, implements the
> createEditor(), setEditorData() and setModelData() methods to build
> the editor widget, and supposedly to set the editor value when the
> model changes, and to set the model when the user interacts with the
> editor. createEditor() seems to be working, since my widgets show up
> in the table and can be interacted with, but neither setEditorData()
> nor setModelData() are ever called when the table widgets are
> displayed, or when I interact with the editor widgets.
> When creating a checkbox widget as an editor, for example, I connect
> its stateChanged() signal to a method in my item delegate which emits
> the commitData() signal:
> where delegate.commit() is:
> def commit(self, *args):
> self.emit(QtCore.SIGNAL("commitData(QWidget *)"),self.sender())
> I assumed that the commitData() signal should tell the table to update
> the model?
> I see the commitData() signal gets sent, if I connect something up to
> that signal, it does get emitted any time I interact with one of the
> editor widgets. But again, the delegate never seems to call
> setModelData() or setEditorData(), so the model is never updated
> (connecting my app up to the itemChanged() signal from the table
> itself shows that, since it never gets that signal).
> So what's the right way to do this? I was trying to convert the
> "Icons" example from the Qt site, which is in C++, over to python -
> specifically the ImageDelegate class which does mostly what I'm trying
> to do:
> But it isn't working for me. Am I missing some connections between the
> editor widgets and the delegate? Or between the delegate and the table?
> Any help appreciated!
More information about the PyQt