Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QListWidget and Multiple Selection

I have a regular QListWidget with couple of signals and slots hookedup. Everything works as I expect. I can update, retrieve, clear etc.

But the UI wont support multiple selections.

How do I 'enable' multiple selections for QListWidget? My limited experience with PyQt tells me I need to create a custom QListWidget by subclassing .. but what next?

Google gave me C++ answers but I'm looking for Python

http://www.qtforum.org/article/26320/qlistwidget-multiple-selection.html

http://www.qtcentre.org/threads/11721-QListWidget-multi-selection

like image 878
Jeffrey Jose Avatar asked Oct 24 '10 14:10

Jeffrey Jose


2 Answers

Unfortunately I can't help with the Python specific syntax but you don't need to create any subclasses.

After your QListWidget is created, call setSelectionMode() with one of the multiple selection types passed in, probably QAbstractItemView::ExtendedSelection is the one you want. There are a few variations on this mode that you may want to look at.

In your slot for the itemSelectionChanged() signal, call selectedItems() to get a QList of QListWidgetItem pointers.

like image 185
Arnold Spence Avatar answered Sep 20 '22 10:09

Arnold Spence


For PyQT4 it's

QListWidget.setSelectionMode(QtGui.QAbstractItemView.ExtendedSelection) 
like image 29
Jeff M. Avatar answered Sep 23 '22 10:09

Jeff M.