Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting Selected Rows Count in QTableWidget - PyQt

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()

like image 780
Sjs Avatar asked Dec 02 '25 13:12

Sjs


1 Answers

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()))
like image 74
ekhumoro Avatar answered Dec 05 '25 03:12

ekhumoro



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!