View Full Version : [qt4 & Xp] resize columns of a QTreeView

2nd March 2006, 14:37
I have this QtreeView 'table' based on a QStandardItemModel 'model'.

model->setHeaderData(0, Qt::Horizontal, tr("Mois"));
model->setHeaderData(1, Qt::Horizontal, tr("Facture"));

I found how I can set the header text, but not how I can resize the columns.
No member in QTreeView does that. And the model should not be involved I guess.
resizeColumnTo Contents does not help me.

So I don't know how I can resize my columns in the view !!

2nd March 2006, 14:41
So I don't know how I can resize my columns in the view !!

You can access the header view by QTreeView::header().
QHeaderView offers you a couple of methods for resizing 'sections'.

2nd March 2006, 14:42
You should access the header (using view's header() method) which is of QHeaderView type. There are some ways to access header sizes there.

2nd March 2006, 14:59
I had seen this possibility as the doc points to it, but I can't get my syntax right :


compile error:
cannot call member function `void QHeaderView::resizeSection(int, int)' without object

I tried several combination but I can't get the QTreeView table linked to QHeaderView...

2nd March 2006, 15:06