[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: [PyQt] QListWidget item editing
From:       J Barchan <jnbarchan () gmail ! com>
Date:       2018-12-16 9:42:29
Message-ID: CABz3M_9dLzLEyvnsHkL-Rjv_NwFmvkf+=zbP7Qb+iHCVk35EhA () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


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

> 
> 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
QStyledItemDelegate
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!
-- 
Kindest,
Jonathan

<https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail>
 Virus-free.
www.avast.com
<https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail>
 <#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>


[Attachment #5 (text/html)]

<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div \
dir="ltr"><div dir="ltr"><div class="gmail_default" \
style="font-family:tahoma,sans-serif"><br></div></div><br><div \
class="gmail_quote"><div dir="ltr">On Sat, 15 Dec 2018 at 18:09, Maurizio Berti \
&lt;<a href="mailto:maurizio.berti@gmail.com">maurizio.berti@gmail.com</a>&gt; \
wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px \
0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid"><div \
dir="ltr"><div dir="ltr"><div dir="ltr"><div \
style="font-family:tahoma,sans-serif"><br \
class="gmail-m_-8701069259396852125gmail-Apple-interchange-newline"><blockquote \
class="gmail_quote" style="margin:0px 0px 0px \
0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid">One \
thing I didn&#39;t like/expect: your Qt reply is that same as at the forum (so I \
accept that&#39;s the way to do it now), you use the  <font \
face="monospace,monospace">QStyledItemDelegate  </font>to get the item being edited \
(from the  <font face="monospace,monospace">QIndex</font>  parameter), I expected \
that to be doable in the  <font face="monospace,monospace">QListWidget  </font>class \
by (somehow) it knowing which item was being edited instead, but it seems that&#39;s \
not the case.</blockquote></div><div dir="ltr"><br></div><div dir="ltr">Well, \
theoretically you could implement the <font face="monospace, monospace">edit()</font> \
virtual protected method (not the slot) of QAbstractItemView instead, but then \
you&#39;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.<br>I read your original question again, and maybe \
it&#39;s better to just reimplement edit() in your case; there also is the virtual \
protected slot <font face="monospace, monospace">closeEditor()</font>  that can help \
with what you need. If the reimplementations are not too complex, it might help you \
completely avoid the QStyledItemDelegate at all.<br>In any case, the index-&gt;item \
conversion is always required, and it&#39;s what QListWidget actually does \
anyway.<br><div><br></div><div>Maurizio</div><div><br></div><div>PS: as a suggestion, \
it&#39;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 &quot;was&quot; 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.</div><div></div></div></div><div><br></div><div><br></div>-- <br><div \
class="gmail-m_-8701069259396852125gmail_signature" dir="ltr">È difficile avere una \
convinzione precisa quando si parla delle ragioni del cuore. - &quot;Sostiene \
Pereira&quot;, Antonio Tabucchi<br><a href="http://www.jidesk.net" \
target="_blank">http://www.jidesk.net</a></div></div></div> \
</blockquote></div><div><br></div><div><div class="gmail_default" \
style="font-family:tahoma,sans-serif">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.</div><div class="gmail_default" \
style="font-family:tahoma,sans-serif"><br></div><div class="gmail_default" \
style="font-family:tahoma,sans-serif">The guy who replied there is a <font \
face="monospace,monospace">QStyledItemDelegate </font>proselytiser and I respect that \
he knows what he is talking about, so I don&#39;t mind using that.   I just thought \
it would all be doable from <font face="monospace,monospace">QListWidget \
</font>without going to the delegate.   I&#39;m not as clever/<em>au fait </em>with \
PyQt/Qt as you guys, and don&#39;t really want to have to go understand the Qt \
sources for this if I don&#39;t have to.   I am looking for the &quot;simplest&quot; \
answer, which for me probably equates to the least lines of code I have to write!   \
Not sure I understand enough about what you&#39;re suggesting as the alternative for \
me to implement it.   One thing that &quot;confuses&quot; me: this is probably a \
<em>dumb</em> thing to ask, but given that I can only write<font \
face="monospace,monospace"> def edit(self)</font> as an override function I don&#39;t \
understand what to do about your:</div><div class="gmail_default" \
style="font-family:tahoma,sans-serif">&gt; Well, theoretically you could implement \
the <font face="monospace, monospace">edit()</font> virtual protected method (not the \
slot) of QAbstractItemView instead</div><div class="gmail_default" \
style="font-family:tahoma,sans-serif">as they both look to me like methods named \
<font face="Courier New">edit()</font>...?</div><div class="gmail_default" \
style="font-family:tahoma,sans-serif"><br></div><div class="gmail_default" \
style="font-family:tahoma,sans-serif">So when I get back to this on Tuesday I think \
I&#39;ll have a look at the <font face="Courier New">QStyledItemDelegate \
</font>approach, which I think I know how to implement, and see whether I can compare \
that against your <font face="monospace,monospace">edit()</font> + <font \
face="monospace,monospace">closeEditor() </font>approach.   If <em>all</em> I have to \
do is override each of these in <font face="Courier New">QListWidget  </font>then \
that would be just fine, but that&#39;s not where they live.   I&#39;m a bit all over \
the place, I just need to find an approach that simple enough for my poor little \
brain!<br>-- <br></div></div><div class="gmail_signature" dir="ltr"><div \
dir="ltr"><div><div dir="ltr"><div><span \
style="font-family:tahoma,sans-serif">Kindest,</span></div><div><span \
style="font-family:tahoma,sans-serif">Jonathan</span></div></div></div></div></div></div></div></div></div></div></div><div \
id="DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2"><br> <table style="border-top:1px solid \
#d3d4de">  <tr>
        <td style="width:55px;padding-top:13px"><a \
href="https://www.avast.com/sig-email?utm_medium=email&amp;utm_source=link&amp;utm_campaign=sig-email&amp;utm_content=webmail" \
target="_blank"><img \
src="https://ipmcdn.avast.com/images/icons/icon-envelope-tick-round-orange-animated-no-repeat-v1.gif" \
alt="" width="46" height="29" style="width: 46px; height: 29px;"></a></td>  <td \
style="width:470px;padding-top:12px;color:#41424e;font-size:13px;font-family:Arial,Helvetica,sans-serif;line-height:18px">Virus-free. \
<a href="https://www.avast.com/sig-email?utm_medium=email&amp;utm_source=link&amp;utm_campaign=sig-email&amp;utm_content=webmail" \
target="_blank" style="color:#4453ea">www.avast.com</a>  </td>
	</tr>
</table><a href="#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2" width="1" \
height="1"></a></div>


[Attachment #6 (text/plain)]

_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
https://www.riverbankcomputing.com/mailman/listinfo/pyqt


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic