Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getting values of table view headers

I'm not able to access to the values of the headers of a table widget.

I'm able to set them like:

self.table_widget.setHorizontalHeaderLabels(words)

I've tried all the methods of header view object without any positive result.

Printing the header value with:

print(self.tableWidget.verticalHeader())

I obtain the object

<PyQt5.QtWidgets.QHeaderView object at 0x10ebc1798>
like image 580
Manuel Zompetta Avatar asked Oct 26 '25 08:10

Manuel Zompetta


1 Answers

You have to iterate using the horizontalHeaderItem():

labels = []
for c in range(self.tableWidget.columnCount()):
    it = self.tableWidget.horizontalHeaderItem(c)
    labels.append(str(c+1) if it is None else it.text())
print(labels)
like image 77
eyllanesc Avatar answered Oct 27 '25 23:10

eyllanesc



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!