How can I enable / disable QTableWidget's horizontal / vertical header?

喜你入骨 提交于 2019-12-23 07:35:24

问题


If I set the horizontalHeaderVisible or verticalHeaderVisible attribute to false in Qt Designer, this works fine. But how can I enable / disable headers in my code? I've been trying something like this:

self.ui.tblContents.horizontalHeaderVisible = False

回答1:


You'd get the header 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)



回答2:


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

Initialize the widget, i mentioned it to make it easy on you to locate the the steps:

self.tableWidget = QTableWidget() 

Hide Horizontal header

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

Hide vertical header

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


来源:https://stackoverflow.com/questions/14910136/how-can-i-enable-disable-qtablewidgets-horizontal-vertical-header

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!