[PyQt] QListWidget item editing

J Barchan jnbarchan at gmail.com
Sun Dec 16 09:42:29 GMT 2018

On Sat, 15 Dec 2018 at 18:09, Maurizio Berti <maurizio.berti at gmail.com>

> 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.
> Maurizio
> 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
> implementation.
> --
> È difficile avere una convinzione precisa quando si parla delle ragioni
> del cuore. - "Sostiene Pereira", Antonio Tabucchi
> http://www.jidesk.net

In my original post here I did feel I had taken the time to pick out the
key points of what I had posted in the Qt forum question without repeating
the whole thing.  Sorry if I failed to do that sufficiently.

The guy who replied there is a QStyledItemDelegate proselytiser and I
respect that he knows what he is talking about, so I don't mind using
that.  I just thought it would all be doable from QListWidget without going
to the delegate.  I'm not as clever/*au fait *with PyQt/Qt as you guys, and
don't really want to have to go understand the Qt sources for this if I
don't have to.  I am looking for the "simplest" answer, which for me
probably equates to the least lines of code I have to write!  Not sure I
understand enough about what you're suggesting as the alternative for me to
implement it.  One thing that "confuses" me: this is probably a *dumb*
thing to ask, but given that I can only write def edit(self) as an override
function I don't understand what to do about your:
> Well, theoretically you could implement the edit() virtual protected
method (not the slot) of QAbstractItemView instead
as they both look to me like methods named edit()...?

So when I get back to this on Tuesday I think I'll have a look at the
approach, which I think I know how to implement, and see whether I can
compare that against your edit() + closeEditor() approach.  If *all* I have
to do is override each of these in QListWidget then that would be just
fine, but that's not where they live.  I'm a bit all over the place, I just
need to find an approach that simple enough for my poor little brain!

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20181216/11741bb0/attachment.html>

More information about the PyQt mailing list