PySide Bugzilla Closed for New Bugs

PySide is now a Qt Add-on and uses the Qt Project's JIRA Bug Tracker instead of this Bugzilla instance. This Bugzilla is left for reference purposes.

Bug 172 - editing a QListWidgetItem stored in a variable makes it impossible to delete
: editing a QListWidgetItem stored in a variable makes it impossible to delete
Status: CLOSED FIXED
Product: PySide
Classification: Unclassified
Component: PySide
: HEAD
: All All
: P5 normal
Assigned To: renato filho
:
: 396
:
  Show dependency treegraph
 
Reported: 2010-02-24 19:06 EET by gt6
Modified: 2010-11-25 17:48 EET (History)
6 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description gt6 2010-02-24 19:06:42 EET
See this test case: http://stuff.moritzg.ch/listdeletebug.py

What doesn't work:
1. click on "New Event" - a new QListWidgetItem gets created
2. click on the new entry
3. hit "edit" - the QListWidgetItem gets a .setText()
4. hit "remove"
---> The item doesn't disappear from the list

What does work:
3. Instead of clicking on "edit", click on "edit directly"
4. hit "remove"
---> The item _does_ get removed from the list.

Note that the only difference between the def editEvent(self) and def
editEventDirectly(self) functions is, that the first one stores the item in a
variable and performs the .setText() on that, while the second sets the text
directly on the item. The second one works, the first does not!
Comment 1 Hugo Parente Lima 2010-10-13 16:17:14 EEST
Would you attach the test case to the bug again? because the link is no longer
valid (error 404)
Comment 2 Hugo Parente Lima 2010-10-13 17:05:28 EEST
I need your original test case, scanning into the deepness of my memory I
rewrote your test case, or at least what I did remenber about it and it worked,
but IIRC you didn't used takeItem method to remove the item, using
removeItemWidget instead, remoteItemWidget method has other meaning, it doesn't
remove the item from the model, it just remove the widget used into the item
delegate if there's one.

Btw, I'll not close the bug until we find the original test case or you give me
thumbs up about the relation of the following test case and yours.

from PySide.QtCore import *
from PySide.QtGui import *


class Foo(QWidget):
    def __init__(self):
        QWidget.__init__(self)
        directEdit = QPushButton("Direct edit")
        indirectEdit = QPushButton("Indirect edit")
        remove = QPushButton("Remove")
        directEdit.clicked.connect(self.directEdit)
        indirectEdit.clicked.connect(self.indirectEdit)
        remove.clicked.connect(self.remove)

        hlayout = QHBoxLayout()
        hlayout.addWidget(directEdit)
        hlayout.addWidget(indirectEdit)
        hlayout.addWidget(remove)

        self.list = QListWidget()
        vlayout = QVBoxLayout()
        vlayout.addLayout(hlayout)
        vlayout.addWidget(self.list)
        self.list.addItem("foo")
        self.list.addItem("bar")
        self.setLayout(vlayout)


    def directEdit(self):
        self.list.currentItem().setText("Direct Edit")

    def indirectEdit(self):
        item = self.list.currentItem()
        item.setText("Indirect Edit")

    def remove(self):
        self.list.takeItem(self.list.currentRow())

if __name__ == '__main__':
    app = QApplication([])
    f = Foo()
    f.show()
    app.exec_()
Comment 3 gt6 2010-10-14 03:13:41 EEST
I'm sorry - I've quit my subscription at that web hosting service. Here's the
original test case repasted:

http://pastie.org/1220074

The remove code is slightly different. But I'm not even sure right now if it's
correct using "removeItemWidget", I think the code might actually be wrong, but
I haven't been coding any Qt for a while now. Still, there's different
behaviour where I don't see why there sould be.

Thanks!
Comment 4 Hugo Parente Lima 2010-10-14 15:22:38 EEST
removeWidgetItem is really the wrong method and it should do nothing in your
example.

The bug happen because it removes the item because this method is decrefing the
item and it *shouldn't*.

When indirect edited it doesn't remove the item because you store it in a
member variable, so a extra ref still exists.

fixed in commit:
pyside/83f8447c9546f53c134a10f02e81abdab88aed3a
Comment 5 renato filho 2010-11-25 17:48:07 EET
released on 1.0.0~beta1