Pysyde/QTableView: openPersistentEditor works only once?
I have a table view that has to display some comboboxes on its 5th column.
So, on init, i set a delegate (previewModeDelegate) and draw some comboboxes:
def initComboBoxes(self): model = self.view.model() self.view.setItemDelegateForColumn(4, previewModeDelegate(self)) for r in range(model.rowCount()): res = self.view.openPersistentEditor(model.index(r, 4))
class previewModeDelegate(QItemDelegate): def __init__(self, parent): QItemDelegate.__init__(self, parent) self.items =  self.items.append("No FX") self.items.append("Motion Blur") self.items.append("DOF") self.parent = parent def createEditor(self, parent, option, index): self.editor = QComboBox(parent) for i in range(len(self.items)): self.editor.addItem(self.items[i]) # getting node, getting the data cNode = index.model().cameraData[index.row()] value = cNode.GetProperty("previewMode") self.editor.connect(self.editor, SIGNAL("currentIndexChanged(int)"), self.cbCallback) self.editor.setCurrentIndex(value) return self.editor def cbCallback(self, value): editor = self.sender() self.parent.view.commitData(editor) self.parent.view.closeEditor(editor, QAbstractItemDelegate.NoHint) def setModelData(self, editor, model, index): value = editor.currentIndex() # getting the node, setting the data cNode = model.cameraData[index.row()] cNode.SetProperty("previewMode", value) return True
everything works fine, i get some nice working comboboxes:
problem is. during the sw usage, i have to reset the model and recreate the comboboxes.
So, in the gui init, i connected the InitComboBoxes method to the the resetModel signal
After i reset the model, the initComboBoxes method is launched but the comboboxes are not reinitialized correctly:
I am still very new to Pyside MVC. I tried tinkering with the code, but with no results. Any help?
Did you check the size of the model when
initComboBoxesis called ?
If it's valid, can you try not replacing the delegate ?
I use PyQt, but pretty similar to PySide. This probably has nothing to do with your problem, but...
self.parent = parent
QItemDelegateinherits all the way from
QObject.parent()method. Is it a good idea to create an instance attribute with the same name as an inherited method?
In your code, you could get rid of that anyway and simply use the existing
parent()method instead. You won't need your own
parentattribute in any of your classes deriving from
thank you guys for your inputs
hi, i checked and the model looks always valid to me.
My impression is that on a model level everything works - in fact, the numbers that i see on the combobox column are coming straight out of it.
Also, I just noticed that if i double click the cell and go into edit mode, I still get my combobox delegate and I can correctly edit the values; the combobox disappears as soon as i'm done with the edit.
I tried moving the setItemDelegateForColumn method around - only in init, after the openPersistentEditor, before it, duplicated...but no luck
good call, didn't know that, I fixed it. But sadly, as you said, that didn't solve the issue
If I connect the rebuild function to a custom signal that I emit just after the endResetModel(), everything works.
Why is that?
Maybe the modelReset signal is not emitted when I expect it to?
modelResetshould be emit after endResetMode.
What version of PySide are you using ?