fancypants-l
fancypants-l

Reputation: 79

Native PyQt function returning selected QTreeWidgetItems in order of selection?

I have a QTreeWidget which uses the QAbstractItemView.ExtendedSelection property, allowing users to shift click and control click items.

I'd like to preform actions on these items based on the order in which they are selected-- I can think of ways to design my own systems to determine the selection order, but is there a native function/property that will return a list of items sorted via selection order?

Thank you for your advice!

Upvotes: 1

Views: 308

Answers (1)

ekhumoro
ekhumoro

Reputation: 120738

The underlying selection model naturally preserves in the order in which items are selected. So you don't really need to do anything special - just iterate over them like this:

for item in treewidget.selectedItems():
    print(item.text(0))

Upvotes: 3

Related Questions