469,625 Members | 1,059 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,625 developers. It's quick & easy.

Removing an item from a QListView in PyQt

Hi,

I am looking for a bit more elaboration on the problem of deleting
elements from a QListsView. I know this is a tricky problem with
references, but I have not been able to extract enough knowledge from
the documentation to solve a specific problem:

In a dialog I have a QListView called referenceList. Entries are added
and deleted from this list with buttons addButton and removeButton
connected with sockets:

----
class IdeaInputBase(QDialog):
def __init__(self,parent = None,name = None,modal = 0,fl = 0):
QDialog.__init__(self,parent,name,modal,fl)
self.connect(self.addButton,SIGNAL("clicked()"),se lf.addNewReferenceSlot)

self.connect(self.removeButton,SIGNAL("clicked()") ,self.removeReferenceSlot)
....
----
class IdeaInput(IdeaInputBase):
def __init__(self):
IdeaInputBase.__init__(self)

def addNewReferenceSlot(self):
self.referenceList.insertItem(QListViewItem(self.r eferenceList, "An
Item"))

def removeReferenceSlot(self):
print "selected has address %s" % (self.referenceList.selectedItem())
self.referenceList.removeChild(self.referenceList. selectedItem())
----
Adding Items by pressing the addButton works fine. I then select one of
the list elements and press the removeButton. This is the output I get.

selected has address <qt.QListViewItem object at 0x1c98f0>
Traceback (most recent call last):
File "./idea_input.py", line 20, in removeReferenceSlot
self.referenceList.removeChild(self.referenceList. selectedItem())
TypeError: argument 1 of QScrollView.removeChild() has an invalid type

I see that I have an address of a QListViewItem, but I am not able to
delete it. What am I obviously doing wrong here?

Kind regards,
--
Svenn

Apr 11 '06 #1
2 6548
Svenn Bjerkem wrote: > In a dialog I have a QListView called
referenceList. Entries are added > and deleted from this list with
buttons addButton and removeButton > connected with sockets: [...] >
def removeReferenceSlot(self): > print "selected has address %s" %
(self.referenceList.selectedItem()) >
self.referenceList.removeChild(self.referenceList. selectedItem()) >
---- > Adding Items by pressing the addButton works fine. I then select
one of > the list elements and press the removeButton. This is the
output I get. > > selected has address <qt.QListViewItem object at
0x1c98f0> > Traceback (most recent call last): > File
"./idea_input.py", line 20, in removeReferenceSlot >
self.referenceList.removeChild(self.referenceList. selectedItem()) >
TypeError: argument 1 of QScrollView.removeChild() has an invalid type
That's because removeChild() is a QScrollView method. You can call this
method because QListView inherits it from QScrollView, but it's not the
method you're looking for. > I see that I have an address of a
QListViewItem, but I am not able to > delete it. What am I obviously
doing wrong here? You need to call your QListView instance's
takeItem() method with the item you want to remove as the argument.
Hope this helps, David

Apr 11 '06 #2
To summarize my previous misformatted post: removeChild() is a
QScrollView method. You can call it because QListView inherits it
from QScrollView, but you need to call your QListView instance's
takeItem() method with the item you want to remove as the argument.
Hope this helps,

David

Apr 11 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by simo | last post: by
2 posts views Thread by Uwe Mayer | last post: by
5 posts views Thread by Bob Parnes | last post: by
reply views Thread by sameer mowade via .NET 247 | last post: by
1 post views Thread by Reinaldo Carvalho | last post: by
7 posts views Thread by =?Utf-8?B?Sm9lbCBNZXJr?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.