[Solved] setItemDelegateForColumn only works for one column?
-
Sorry, the following is accounted for by Python's garbage collector. There is an obscure note in the doc "QAbstractItemView does not take ownership of delegate." Which means that if I don't keep a reference, soon it will go out of scope and be scavenged. So when I changed the code to store a reference to each delegate in the main object, then all three columns began to work.
I am making a table with six columns. Col's 1, 2 and 3 are to be editable, two with combo boxes and one with a spinbox. So I made three item delegates, one for each column. Individually, each one tests as expected. BUT -- when I try to apply the delegates to all 3 columns, as in (PyQt code):
@
self.view.setItemDelegateForColumn(2,actionDelegate())
self.view.setItemDelegateForColumn(3,folioDelegate())
self.view.setItemDelegateForColumn(1,formatDelegate())
@
...only the last-executed call takes effect. The other two columns revert to the default delegate for input. In the above example, column 1 will have my delegate, 2 & 3 are default. But if column 3's delegate is set last, it will have its custom delegate, and 1 & 2 will default. Is this a bug or restriction in Qt, or am I just overlooking something obvious?(p.s. I realize that I could just make one custom delegate for all items, and in each method (createEditor, setEditorData, setModelData) I could have code to say, well, if it is column 1, do this, column 2, do that, column 3, the other -- seems needlessly complex, if only set...ForColumn worked.)