Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
[Solved] setItemDelegateForColumn only works for one column?
dcortesi last edited by
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):
...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.)