PDA

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



incapacitant
2nd March 2006, 13: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 !!

jpn
2nd March 2006, 13: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'.

wysota
2nd March 2006, 13: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.

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



table->setHeader(QHeaderView::resizeSection(0,100));



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...

jpn
2nd March 2006, 14:06
table->header()->resizeSection(0,100);