[PyQt] QListWidget item editing

Maurizio Berti maurizio.berti at gmail.com
Sat Dec 15 18:08:19 GMT 2018

> One thing I didn't like/expect: your Qt reply is that same as at the forum
> (so I accept that's the way to do it now), you use the
> QStyledItemDelegate to get the item being edited (from the QIndex parameter),
> I expected that to be doable in the QListWidget class by (somehow) it
> knowing which item was being edited instead, but it seems that's not the
> case.

Well, theoretically you could implement the edit() virtual protected method
(not the slot) of QAbstractItemView instead, but then you'll have to check
that the trigger matches the current editTriggers and, possibly, the
relative QEvent which can sometimes be a bit tricky if you are not really
careful. Take a look at the Qt sources of edit() of both QAbstractItemView
and QListWidget as a reference.
I read your original question again, and maybe it's better to just
reimplement edit() in your case; there also is the virtual protected slot
closeEditor() that can help with what you need. If the reimplementations
are not too complex, it might help you completely avoid the
QStyledItemDelegate at all.
In any case, the index->item conversion is always required, and it's what
QListWidget actually does anyway.


PS: as a suggestion, it's better to specify keypoints even when referring
to an existing question online: I read that forum message this morning, but
when I answered I forgot about the actual purpose of your code, then I just
focused on the PyQt questions. While that "was" your question, the original
one was focused on a slightly different objective, making this thread more
like an XY-Problem, since you could probably avoid the delegate

È difficile avere una convinzione precisa quando si parla delle ragioni del
cuore. - "Sostiene Pereira", Antonio Tabucchi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20181215/6494b180/attachment.html>

More information about the PyQt mailing list