Select multiple items in QListWidget programmatically
Asked Answered
B

2

8

It's possible to select a single item/row, but I want to set multiple items selected (the widget is configured to allow that). Is it possible?

Banjo answered 10/1, 2013 at 21:4 Comment(0)
J
16

You can find all QListWidgetItem* items you want to select and use QListWidgetItem::setSelected on them. This should support multiple selection if the list is configured for QAbstractItemView::ExtendedSelection.

Jacobus answered 10/1, 2013 at 21:15 Comment(0)
I
1

I've found this question while looking for the same answer. However, I am using Python (PyQt5) with Qt Creator.

Using PyQt5 you can set the SelectionMode by using:

from PyQt5 import QtWidgets    


QtWidgets.QListWidget.setSelectionMode(2)

where

  • SelectionMode = 0 => NoSelection
  • SelectionMode = 1 => SingleSelection
  • SelectionMode = 2 => MultiSelection
  • SelectionMode = 3 => ExtendedSelection
  • SelectionMode = 4 => ContiguousSelection

Reference

In Qt Creator you find this option here: enter image description here

Immigrate answered 18/6, 2020 at 14:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.