In the python plugin, I'm developing, I need to retrieve the number of selected rows in a QTableWidget. I can loop through each row of the QTableWidget and check them whether it is selected or not. Instead, Is there a straightforward way to get the selected rows count of a QTableWidget in PyQt?
Something like:
QTableWidget.selectedRowsCount()
If you want the number of rows that are fully selected (i.e. as when clicking on a row header):
len(tableWidget.selectionModel().selectedRows())
But if you want rows which just have at least one cell selected:
len(set(index.row() for index in tableWidget.selectedIndexes()))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With