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

List:       pykde
Subject:    Re: [PyQt] Can't delete a wanted item in a treeView
From:       Maurizio Berti <maurizio.berti () gmail ! com>
Date:       2019-05-31 14:13:58
Message-ID: CAPn+-XSz58z2B6Q==HP+aC8qE2PKEyt264gnhFx_V7oDGhJwjw () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


Il giorno ven 31 mag 2019 alle ore 09:51 Gottfried Müller <
gottfried.mueller@gmx.de> ha scritto:

> Hello,
>
> in the example I created a tree with 3 items ("aaa", "bbb", "ccc"). In a
> context menu I want to remove the items "bbb" or "ccc". I get always the
> correct item, but I have no idea how to delete this item. May action
> takes always the item "aaa". In another menu action ("find item text") I
> searched for a reason. I get always the row=0 and column=0 of the model
> index. Also a findItems call delivers no results. I have no idea whats
> wrong.
>

You're trying to remove an item which is child of another one, while
QStandardItemModel.takeItem() only works for "root" items.
You need to remove the item's row from the item parent:

        [...]
        delCase01.triggered.connect(lambda: self.delTakeItem(item))
        menu.exec_(self.mapToGlobal(pos))

     def delTakeItem(self, item):
         item.parent().removeRow(item.row())

Cheers,
Maurizio

-- 
È difficile avere una convinzione precisa quando si parla delle ragioni del
cuore. - "Sostiene Pereira", Antonio Tabucchi
http://www.jidesk.net

[Attachment #5 (text/html)]

<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"></div><div \
class="gmail_quote"><div dir="ltr" class="gmail_attr">Il giorno ven 31 mag 2019 alle \
ore 09:51 Gottfried Müller &lt;<a \
href="mailto:gottfried.mueller@gmx.de">gottfried.mueller@gmx.de</a>&gt; ha \
scritto:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px \
0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hello,<br> <br>
in the example I created a tree with 3 items (&quot;aaa&quot;, &quot;bbb&quot;, \
&quot;ccc&quot;). In a <br> context menu I want to remove the items &quot;bbb&quot; \
or &quot;ccc&quot;. I get always the <br> correct item, but I have no idea how to \
delete this item. May action <br> takes always the item &quot;aaa&quot;. In another \
menu action (&quot;find item text&quot;) I <br> searched for a reason. I get always \
the row=0 and column=0 of the model <br> index. Also a findItems call delivers no \
results. I have no idea whats <br> \
wrong.<br></blockquote><div><br></div><div>You&#39;re trying to remove an item which \
is child of another one, while  </div><div>QStandardItemModel.takeItem() only works \
for &quot;root&quot; items.</div><div>You need to remove the item&#39;s row from the \
item parent:</div><div><br></div><div><div><font face="courier new, monospace">       \
[...]</font></div><div><font face="courier new, monospace">            \
delCase01.triggered.connect(lambda: self.delTakeItem(item))</font></div><div><font \
face="courier new, monospace">            \
menu.exec_(self.mapToGlobal(pos))<br></font></div><div><font face="courier new, \
monospace"><br></font></div><div><font face="courier new, monospace">        def \
delTakeItem(self, item):</font></div><div><font face="courier new, monospace">        \
item.parent().removeRow(item.row())</font></div></div><div><br></div><div>Cheers,</div><div>Maurizio \
</div></div><div><br></div>-- <br><div dir="ltr" class="gmail_signature">È 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></div></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