xwsz
xwsz

Reputation: 37

How to get rid of the blank area at the bottom of tableview

enter image description here

There's always an bland area at the bottom of the tableview of QTableWidget.

How can I get rid of this blank area, and let the tableview only display the row and column according to the given data?

Upvotes: 2

Views: 249

Answers (1)

eyllanesc
eyllanesc

Reputation: 243897

You have to set Stretch as resizeMode to the verticalheader():

import sys
from PyQt5 import QtWidgets, QtCore, QtGui

if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    w = QtWidgets.QTableView()
    w.setModel(QtGui.QStandardItemModel(4, 4))
    w.verticalHeader().setSectionResizeMode(QtWidgets.QHeaderView.Stretch)
    w.horizontalHeader().setSectionResizeMode(QtWidgets.QHeaderView.Stretch)
    w.show()
    sys.exit(app.exec_())

enter image description here

Upvotes: 1

Related Questions