PDA

View Full Version : QHeaderView not resizing



ericwny
5th June 2008, 16:42
I am have been programming a tableview but I have a nagging problem for which I haven't been able to find any relevant posts.
I have the following code:



AttributeMapModel* model = new AttributeMapModel( canonical_fields, mapped_fields, user_fields ) ;
AttributeDelegate* item_delegate = new AttributeDelegate;
ui.AttributeMappingTable->setModel( model );

model->setHeaderData( 0, Qt::Horizontal, "User Fields", Qt::DisplayRole );
model->setHeaderData( 1, Qt::Horizontal, "Rules", Qt::DisplayRole );

ui.AttributeMappingTable->setItemDelegate( item_delegate );
ui.AttributeMappingTable->setEditTriggers( QAbstractItemView::CurrentChanged |
QAbstractItemView::AnyKeyPressed );

ui.AttributeMappingTable->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
ui.AttributeMappingTable->verticalHeader()->setResizeMode(QHeaderView::Stretch);
ui.AttributeMappingTable->verticalHeader()->setStretchLastSection(true);


The horizontal header resizes as specified but the vertical header leaves space at the bottom after the last row which, if the mouse cursor enters it, causes an assert in QHeaderView::setSectionSize(). Q_ASSERT(visual != -1); This is a nuisance but the sizing is aethestically unpleasing itself. Am I missing something?

Note: I am developing under Qt 4.0.1 I hope this doesn't require an upgrade.

wysota
5th June 2008, 17:15
I'm not sure stretching the vertical header is supported... It wouldn't make much sense in most cases, I guess...

ericwny
5th June 2008, 18:22
Well, that may be right but then an assert (for vertical headers) should not be the result. One which you can't just ignore - at least I can't seem to get past it by pressing the ignore button. The assert (or others) keeps popping up. Could one, at least, crop the header to the rows?

wysota
5th June 2008, 19:36
Well, that may be right but then an assert (for vertical headers) should not be the result.
Yes, that obviously true.

jpn
6th June 2008, 11:03
Note: I am developing under Qt 4.0.1 I hope this doesn't require an upgrade.
Wow, that's pretty old... 3 years? Just be aware that the model view framework (and almost everything else in Qt for that matter) has been improved a lot since then. Not only new functionality was added but also lots of bug fixes were applied. Just curious, why do you resist updating? Are you one of those commercial customers whose license period ended? :)