PDA

View Full Version : can't qry QlistWidgetItem after changing selectionMode



Sorath
2nd July 2015, 10:09
Hey guys, I'm doing PySide, I hope that's not a problem for this forum? Since it's very close to PyQt I will try.

first I disconnect the previous function associated with the QListWidget click command
I'm chaging the selection mode for my QListWidget and calling a new function on click
(first question, do I also need to disconnect the old selection mode that was assigned or is setSelectionMode overriding the old one?)


self.listWidget_lights.itemClicked.disconnect(self .funcUpdateLights)
self.listWidget_filters.setSelectionMode (QtGui.QAbstractItemView.MultiSelection)
self.listWidget_filters.itemClicked.connect(self.c onnectingFiltersFunc)


then I call:



def connectingFiltersFunc(self):
item = QtGui.QListWidgetItem(self.listWidget_filters)
print item
print self.listWidget_filters.indexFromItem(item).row()

and this is already behaving weird.
If I click on one of my items in the widget multiple times to select or deselect it needs two clicks to select or deselect.
Now even when I click the same item I always get a different result as pointer.
print item returns when the same item is clicked:
<PySide.QtGui.QListWidgetItem object at 0x000000009B61D348>
<PySide.QtGui.QListWidgetItem object at 0x000000009B61D988>
<PySide.QtGui.QListWidgetItem object at 0x000000009B61D808>
<PySide.QtGui.QListWidgetItem object at 0x000000009B61D4C8>
<PySide.QtGui.QListWidgetItem object at 0x000000009B61DC88>
<PySide.QtGui.QListWidgetItem object at 0x000000009B61D788>
<PySide.QtGui.QListWidgetItem object at 0x000000009B61DC48>
<PySide.QtGui.QListWidgetItem object at 0x000000009B61D708>
<PySide.QtGui.QListWidgetItem object at 0x000000009B61DD88>
<PySide.QtGui.QListWidgetItem object at 0x000000009B61D5C8>


self.listWidget_filters.indexFromItem(item).row()
this one looks in a dictionary to find the right entry and return what entry was just selected.
this returns no matter what Item I select or deselect:

19
20
21
22
23
24
25
26
27
28
.
.
.


anyone any idea what's going on?
I really just started with Pyside /qt

thank you

yeye_olive
2nd July 2015, 11:22
I do not know PySide, but doesn't this line

item = QtGui.QListWidgetItem(self.listWidget_filters)
allocate and insert a new item in the listWidget_filters list? This would explain why, every time you click on some item in the list, item has a fresh address and its row number has been incremented.

The item that was clicked is passed as a parameter to the QListWidget::itemClicked() signal. I do not know how it maps to PySide, but maybe all you have to do is to append a parameter to connectingFiltersFunc.

Alternatively, since you use multiselection, you could call QListWidget::selectionModel() to get the selection model, and connect to its selectionChanged() signal to monitor changes in the set of selected items.

As for you first question, I do not understand what you mean by "disconnect the old selection mode that was assigned", but all you have to do to change the selection mode is call setSelectionMode, which you do correctly.

Sorath
2nd July 2015, 11:40
you are right! I was beeing stupid, sorry for that, I forgot that I can just pass item along to the new function and just print it from there.
Everything working now!