LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-06-2012, 03:39 AM   #1
devilboy09
Member
 
Registered: Nov 2011
Location: Iran
Distribution: Debian, CentOS, LFS, CloudLinux
Posts: 377

Rep: Reputation: 10
remove a row from QListWidget()


i'm using python and Qt4.i created a qlistwidget and added some elements like this:
Code:
self.listWidget = QtGui.QListWidget()
		shares = []
		shares = open('/etc/exports', 'r')
		for item in shares:
			if not re.search('^#', item):
				self.listWidget.addItem(item)
i could retrieve the current row :
Code:
curRow = self.listWidget.currentRow()
but i can't remove it from the list.i searched the Qt4 library and there is no method for doing so.is there ant way to remove an item from a qlistwidget ?
 
Old 07-06-2012, 05:46 AM   #2
eSelix
Senior Member
 
Registered: Oct 2009
Location: Wroclaw, Poland
Distribution: Arch, Kubuntu
Posts: 1,281

Rep: Reputation: 320Reputation: 320Reputation: 320Reputation: 320
Of course it is - removeItemWidget(QListWidgetItem). And QListWidgetItem can be found from row number by method item(). Or simpler, use currentItem() to get current QListWidgetItem.

Last edited by eSelix; 07-06-2012 at 05:47 AM.
 
Old 07-06-2012, 07:58 AM   #3
devilboy09
Member
 
Registered: Nov 2011
Location: Iran
Distribution: Debian, CentOS, LFS, CloudLinux
Posts: 377

Original Poster
Rep: Reputation: 10
that's funny because i did what you propose and it didin't work.here's my code :
Code:
curItem = self.listWidget.currentItem()
self.listWidget.removeItemWidget(curItem)
when i run my app nothing happens !
 
Old 07-06-2012, 08:55 AM   #4
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,241

Rep: Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322
Try takeItem instead of removeItemWidget.

From the same page:

Quote:
To remove items from the list, use takeItem().

Last edited by dugan; 07-06-2012 at 09:00 AM.
 
Old 07-06-2012, 09:22 AM   #5
devilboy09
Member
 
Registered: Nov 2011
Location: Iran
Distribution: Debian, CentOS, LFS, CloudLinux
Posts: 377

Original Poster
Rep: Reputation: 10
thank you dugan i used takeItem and it did work.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Remove duplicate entries on a row sebelk Programming 2 11-01-2010 09:43 AM
[ask awk] remove certain row in a column dhodho Programming 18 06-08-2010 09:36 AM
gnome-terminal is missing one pixel row and its an important row rednuht Linux - General 1 12-24-2009 10:30 AM
Shell script to parse csv-like output, row by row utahnix Linux - General 8 12-08-2007 05:03 AM
bash script - remove header row from csv file pljvaldez Programming 5 08-30-2006 11:05 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:16 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration