How Do I Resize Rows With Setrowheight And Resizerowtocontents In Pyqt4?
I have a small issue with proper resizing of rows in my tableview. I have a vertical header and no horizontal header. I tried: self.Popup.table.setModel(notesTableModel(datainput))
Solution 1:
For me, both setRowHeight
and resizeRowsToContents
work as expected. Here's the test script I used:
from PyQt4 import QtCore, QtGui
class Window(QtGui.QWidget):
def __init__(self, rows, columns):
super(Window, self).__init__()
self.table = QtGui.QTableView(self)
self.table.horizontalHeader().setVisible(False)
layout = QtGui.QVBoxLayout(self)
layout.addWidget(self.table)
model = QtGui.QStandardItemModel(rows, columns, self.table)
self.table.setModel(model)
text = 'some long item of text that requires word-wrapping'
for column in range(model.columnCount()):
self.table.setColumnWidth(column, 150)
for row in range(model.rowCount()):
item = QtGui.QStandardItem(text)
model.setItem(row, column, item)
# self.table.setRowHeight(row, 100)
self.table.resizeRowsToContents()
if __name__ == '__main__':
import sys
app = QtGui.QApplication(sys.argv)
window = Window(4, 3)
window.setGeometry(800, 150, 500, 250)
window.show()
sys.exit(app.exec_())
And here's what it looks like:
Post a Comment for "How Do I Resize Rows With Setrowheight And Resizerowtocontents In Pyqt4?"