Hello!

I tried your code and with my OS (Ubuntu 10.10), it works great, both ways give the same result! Instead you can also try the .resizeColumnsToContents() functions. This is a nice way to adjust the column width to the needed width.

Have a nice day!
Aaron






On 25.02.2011 01:07, rulfzid wrote:
I'm finding I can't programmatically resize a column in a QTableView with setColumnCount().

The function does seem to work with QTreeViews though, which is weird.

I've found a workaround, using tableview.horizontalHeader().resizeSection(col, pixels), but just wondering if this a bug somewhere.

Simple code to see the behavior:

********************
#!/usr/bin/python

from PySide.QtCore import *
from PySide.QtGui import *
import sys

app = QApplication(sys.argv)

model = QStandardItemModel()

model.setHeaderData(0, Qt.Horizontal, "Date")
model.setHeaderData(1, Qt.Horizontal, "Time")
model.setHeaderData(2, Qt.Horizontal, "Proc")

model.setItem(0, 0, QStandardItem("First"))
model.setItem(0, 1, QStandardItem("Second"))
model.setItem(0, 2, QStandardItem("Third"))

table = QTableView()
table.setModel(model)
# table.setColumnWidth(0, 150) # <--- this doesn't work!
table.horizontalHeader().resizeSection(0, 150)


vbox = QVBoxLayout()
vbox.addWidget(table)

dialog = QDialog()
dialog.setLayout(vbox)
dialog.resize(400, 400)
dialog.show()

sys.exit(app.exec_())
********************


_______________________________________________
PySide mailing list
PySide@lists.openbossa.org
http://lists.openbossa.org/listinfo/pyside

_______________________________________________
PySide mailing list
PySide@lists.openbossa.org
http://lists.openbossa.org/listinfo/pyside

Reply via email to