473,387 Members | 1,318 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 7005
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: simo | last post by:
OK, so I'm at the stage where I want to make a choice between wxPython and PyQt. Currently I'm using wxPython mainly due to the fact that it has GPL Linux and Windows versions. I prefer Qt to...
2
by: Uwe Mayer | last post by:
Hi, Using PyQt I got a QListView with about 800 entries now (but its intended to be scalable up to about 3000). The first column contains numerical data. Now Qt does the sorting all by its self...
5
by: Bob Parnes | last post by:
I cannot find a reference on identifying multiple selections in QListView. Apparently one has to iterate through all the items and test each individually, but I don't know how to do the iteration....
2
by: Erwan Adam | last post by:
Hi all, I try to introduce tooltips in my application written in PyQt (more precisly, in the menubar of my application) but I can't find a way to get the QRect instance associated to a QMenuBar...
0
by: sameer mowade via .NET 247 | last post by:
Hello All, I have problem while dynamically removing row from the Datagrid which i have added dynamically as shown in the following code snippet. The problem is that while removing dynamically...
66
by: Cor | last post by:
Hi, I start a new thread about a discussion from yesterday (or for some of us this morning). It was a not so nice discussion about dynamically removing controls from a panel or what ever. It...
7
by: Flavio | last post by:
Hi, I have a QListview widget that allows me to store a bunch of strings in it. This strings can be visualized, sorted, selected, etc. My Problem is that I cant find a way to get the user...
1
by: Reinaldo Carvalho | last post by:
Hi, I programming with qt module and i have a qWidgetTab with a qListView inside, and i need update the qListView every 5 seconds, how do this on transparent mode to user. I do a function to...
7
by: =?Utf-8?B?Sm9lbCBNZXJr?= | last post by:
I have created a custom class with both value type members and reference type members. I then have another custom class which inherits from a generic list of my first class. This custom listneeds...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.