Planned maintenance has been done but it did not solve the problem. So work will continue on this and a new time for trying updates will be announced asap.
Pysyde/QTableView: openPersistentEditor works only once?
-
Hi guys,
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))
the delegate:
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 signalself.cameraModel.modelReset.connect(self.initComboBoxes)
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?
Ty,
Federico
-
Hi,
Did you check the size of the model when
initComboBoxes
is called ?
If it's valid, can you try not replacing the delegate ?
-
@dammilo
I use PyQt, but pretty similar to PySide. This probably has nothing to do with your problem, but...self.parent = parent
QItemDelegate
inherits all the way fromQObject.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 ownparent
attribute in any of your classes deriving fromQObject
.
-
thank you guys for your inputs
@SGaist
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
@JonB
good call, didn't know that, I fixed it. But sadly, as you said, that didn't solve the issue
-
Breakthrough!
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?
-
modelReset
should be emit after endResetMode.What version of PySide are you using ?
-
@SGaist sorry if I'm so late, I wasn't notified about your post.
I'm using PySide 1.2. I am working inside 3dsmax 2017 and I have to use what Autodesk provides me - I have no choice about this.