QTableWidget/View resizeColumnsToContents not respected until scroll (PyQt4)
The columns of my table do not resize to contents until you scroll to an item requiring the column be expanded AND resize the splitter pane. Resizing the entire window has the same effect as it also resizes the splitter. My table requires persistent editors, and you will see at row 16 there is a table with 50 columns, which should...after calling 'resizeColumnsToContents' determine the width of column 0. However it will not resize until you scroll down to it and trigger a splitter resize.
Code:
from PyQt4 import QtCore,QtGui
import sys
spl.
addWidget(QtGui.
QLabel('Filler'))
# create table
def __init__(self):
super(tbl,self).__init__()
self.setRowCount(20)
self.setColumnCount(2)
self.horizontalHeader().setStretchLastSection(False)
self.
horizontalHeader().
setResizeMode(QtGui.
QHeaderView.
ResizeToContents) self.
verticalHeader().
setResizeMode(QtGui.
QHeaderView.
ResizeToContents) self.setItemDelegate(delg(self))
# persist editors
for x in xrange(0,self.rowCount()):
for y in xrange(0,self.columnCount()):
for x in xrange(0,self.rowCount()):
for y in xrange(0,self.columnCount()):
self.openPersistentEditor(self.item(x,y))
self.resizeColumnsToContents()
# create item delegate
def __init__(self,parent):
super(delg,self).__init__(parent)
def createEditor(self,parent,option,index):
if index.column() == 1:
if index.row() == 15:
t.setRowCount(5)
t.setColumnCount(50)
return t
t = tbl()
spl.addWidget(t)
mw.setCentralWidget(spl)
# add and show
mw.show()
sys.exit(app.exec_())
Is there a way to force the table to respect the size of all columns? I have tried overwriting the minimumSizeHint for the editor table but get quirky results, eg: the second column will be painted ontop of the editor table....until I resize the splitter which triggers something....a repaint?
Re: QTableWidget/View resizeColumnsToContents not respected until scroll (PyQt4)
You need to call resizeColumnsToContents() when every QTrewWidget is scrolled, and when every QTreeWidget has items added/removed.