Question

i'm just searching in the docu and can not find the solution for the following two problems with QListWidget:

a) i would like to deselect (deactivate) items in the QListWidget from the software (i mean code)

b) i use multiple selection: setSelectionMode(QAbstractItemView.MultiSelection) I would like to pre-select more than one item from the code. If i use setCurrentRow() i can only select on item (it toggles the selected item). How can i do multiple selections?

Your help is very welcome

Was it helpful?

Solution

Both of those could be done with the setSelected method of QListWidgetItems.

# select item
listWidget.item(row).setSelected(True)

# deselect item
listWidget.item(row).setSelected(False)

You can do this for multiple items and as long as you have MultipleSelection enabled, it would select/deselect those items.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top