pyqt QTablewidget remove scrollbar to show full table

纵然是瞬间 提交于 2019-11-30 14:43:36
eyllanesc

If you just want to delete the Scrollbar you must use:

{QtableWidget}.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
{QtableWidget}.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)

If you want to show the expanded QTableWidget, add this to the end of the setData() method:

self.setMaximumSize(self.getQTableWidgetSize())
self.setMinimumSize(self.getQTableWidgetSize())

and define getQTableWidgetSize(self) like this:

def getQTableWidgetSize(self):
    w = self.verticalHeader().width() + 4  # +4 seems to be needed
    for i in range(self.columnCount()):
        w += self.columnWidth(i)  # seems to include gridline (on my machine)
    h = self.horizontalHeader().height() + 4
    for i in range(self.rowCount()):
        h += self.rowHeight(i)
    return QtCore.QSize(w, h)

Note: The function getQTableWidgetSize is a conversion of the code in C ++ to python of the following post: How to determine the correct size of a QTableWidget?

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