PDA

View Full Version : QListWidget muti-selection problem



mohsin7998
25th October 2012, 15:55
Hi Everybody.

Need help with a problem.

I have implemented a QListWidget and populated it with some entries. Now I want the following functionality.

1. When I click on a single item, a Single Click event should be execute. Using "itemClicked" and is working fine.
2. For double click, I am using "itemDoubleClicked"

The problem is how to select multiple items and then trigger a signal? I tried "itemSelectionChanged" but whenever I select an item to include it to my selection, Single Click event is triggered and I dont want that.

If I select 5 items, then 5 Single Click events are getting triggered.

I am using Python 2.7.3, 64 bit with Qt 4.7
Any help would be appreciated.

Mohsin

Gokulnathvc
26th October 2012, 10:22
Could you elaborate why you need to choose multiple items from the QListWidget?

mohsin7998
26th October 2012, 11:23
Thanks for the reply Gokulnathvc.

I am making a list of movies using QListWidget. What I want to do is that, when I single click an item, in the list, my call back function should display the properties of that item. And when I select multiple item by using mouse or keyboard, another event should get triggered and it should return me all the selected items. I am still using the single click function for it and then deciding on the number of items selected to make the decision. Using the following code:

def single_click_function (self, event):
items = self.unsubmittedList.selectedItems() #unsubmittedList is QListWidget
# items = self.unsubmittedList.GetItems()
# selected = self.unsubmittedList.GetSelections()
if self.WIN_32:
if len(selected) == 1: #If I select 1 item
version = items[selected[0]]
for ver in self.unsubmitted_versions:
if version == ver["code"]:
time = datetime.fromtimestamp(mktime(ver["created_at"].timetuple()))
self.rangeText.SetLabel(ver["frame_range"])
self.descText.SetLabel(str(ver["description"]))
self.shotRangeText.SetLabel(ver["render_range"])
self.createdText.SetLabel(time.strftime("%d/%m/%Y %H:%M"))
else: #If more than one item
self.rangeText.SetLabel("")
self.descText.SetLabel("")
self.shotRangeText.SetLabel("")
self.createdText.SetLabel("")

path = '"'
for ver1 in self.unsubmitted_versions: #unsubmitted_versions contains my movies.
for item in selected:
if ver1["code"] == items[item]:
path += ver1["sg_uploaded_movie"]["local_path_windows"] + '" "'

path = path[:-2]
path_win = path

if self.qt_process:
try:
self.qt_process.terminate()
except:
pass

if path:
cmd = self.player + ' ' + path_win
self.qt_process = Popen(shlex.split(cmd))
else:
self.rangeText.SetLabel("")
self.descText.SetLabel("")
self.shotRangeText.SetLabel("")
self.createdText.SetLabel("")


This code was working fine on wx but now I am using Qt and dont know why it is not working now.

Any help would be appreciated.


Cheers

Gokulnathvc
26th October 2012, 11:58
Better use another QListWidget to list the selected list of entries from the List Widget. That could be better. Just populate the second ListWidget with the list of items selected from the first ListWidget.

Ashkan_s
26th October 2012, 11:58
This is perhaps possible to implement a signal which is emitted when a selected item is clicked. Then connect that signal to the slot you want. Probably by connection the QListWidget::itemClicked to a slot which checks whether the item was selected before clicking (a click should toggle the selection state).

mohsin7998
26th October 2012, 12:15
I am looking into mouseReleaseEvent now and I think it would be a good idea.

But it is not working in my QlistWidget, it only triggers an event when clicked on the main window.

Need to override it in my QlistWidget but dont know how to.

Any help would be appreciated.

Cheers

Gokulnathvc
26th October 2012, 12:23
Refer this link : http://tamss60.tamoggemon.com/2010/07/18/long-tap-context-menus-and-qt-for-symbian/

mohsin7998
29th October 2012, 11:25
Thanks mate.

I am using python and the link is a bit confusing.

I tried to apply the same logic using python but its not working.

The mouse release event is working outside the List (On the main Widget) but not in the list where i want it to.

Hope u understand my problem.

I have been told to override the mouse release event but that one too i snot working.

Many thanks,
Mohsin