PDA

View Full Version : How to make headers fixed sized? (QTableWidget)



macias
12th August 2007, 11:19
Hello,

I would like to make vertical headers fixed size -- i.e. so the user could not just drag the small separation line between cells in headers to make rows bigger or smaller.

I though that resize mode for headers will do the trick however, after comparison:


verticalHeader()->setResizeMode(QHeaderView::Fixed);
horizontalHeader()->setResizeMode(QHeaderView::Interactive);


I see absolutely no difference in behaviour -- I mean, both are interactively resizeable.

Thank in advance for your help.

have a nice day, bye

jpn
12th August 2007, 11:24
I though that resize mode for headers will do the trick however, after comparison:


verticalHeader()->setResizeMode(QHeaderView::Fixed);
horizontalHeader()->setResizeMode(QHeaderView::Interactive);


I see absolutely no difference in behaviour -- I mean, both are interactively resizeable.
Something must be mixing it up. QHeaderView::Fixed should do the trick. At least it does for me with Qt 4.2.3 and 4.3.0. :)

macias
12th August 2007, 12:06
Something must be mixing it up. QHeaderView::Fixed should do the trick. At least it does for me with Qt 4.2.3 and 4.3.0. :)

Could persistent editors for each cell be the cause? I use Qt 4.3.0.

I set non-clickable flag for each header, but I tried with and without -- still fixed mode does not work.

have a nice day, bye

jpn
12th August 2007, 12:26
I assume something minimal like this works:


#include <QtGui>

int main(int argc, char* argv[])
{
QApplication a(argc, argv);
QTableWidget table(5, 2);
table.horizontalHeader()->setResizeMode(QHeaderView::Fixed);
table.verticalHeader()->setResizeMode(QHeaderView::Fixed);
for (int row = 0; row < table.rowCount(); ++row)
{
for (int col = 0; col < table.columnCount(); ++col)
{
QTableWidgetItem* item = new QTableWidgetItem;
table.setItem(row, col, item);
table.openPersistentEditor(item);
}
}
table.show();
return a.exec();
}

Could you try filling the example above with steps you've made in the actual project to make the example reproduce the problem?

macias
13th August 2007, 15:57
JPN, thank your for the answer.

I were extending and extending this small example code, and when it reached 210 lines and I didn't manage to reproduce the fixed/interactive bug I was a bit worried :-)

But luckily I pinned it down -- with each setRowCount or setColumnCount the resize mode is resetted! However, and this is really odd, when you create your table not like this
QTableWidget(parent)
but
QTableWidget(0,0,parent)
you can later on setColumn/Row count as you like and still resize mode will be properly kept.

Once again, thank you for your help.

have a nice day, bye