How to enable / disable horizontal / vertical header of QTableWidget?

If I set the horizontalHeaderVisible or verticalHeaderVisible attribute to false in Qt Designer it works fine. But how do I enable or disable headers in my code? I tried something like this:

self.ui.tblContents.horizontalHeaderVisible = False

      

+6


source to share


2 answers


You will get a title and .hide()

(or .setVisible(False)

:



self.ui.tblContents.horizontalHeader().hide()
# or
# self.ui.tblContents.horizontalHeader().setVisible(False)

self.ui.tblContents.verticalHeader().hide()
# or
# self.ui.tblContents.verticalHeader().setVisible(False)

      

+12


source


In case you want to do it using QTableWidget () for Python37 PyQt5. Here are the steps to hide both Vertical and Horizontal:



Initialize the widget, I mentioned it to make it easier to find steps:

self.tableWidget = QTableWidget() 

      

Hide horizontal header

self.tableWidget.horizontalHeader().setVisible(False)

      

Hide vertical header

self.tableWidget.verticalHeader().setVisible(False)

      

0


source







All Articles