Re: Can't delete a wanted item in a treeView

Maurizio Berti <[email protected]>
Newsgroups gmane.comp.python.pyqt-pykde
Message-ID <CAPn+-XSz58z2B6Q==HP+aC8qE2PKEyt264gnhFx_V7oDGhJwjw@mail.gmail.com>
Il giorno ven 31 mag 2019 alle ore 09:51 Gottfried Müller <
[email protected]> 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

_______________________________________________
PyQt mailing list    [email protected]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.