PDA

View Full Version : Resizing QTableView's horizontalHeader



Jimmy2775
19th December 2006, 21:20
Hello there,

I am using a QTableView. One of the calls I'm making to the QTableView is this:

mTableView->horizontalHeader()->setFont( someFont );
I had noticed that if I used a large sized font, the header would be too short to display its text, so I overrode the header's setFont method in the following way:

void GridHeader::setFont( const QFont & aFont )
{
int bufferSize = height() - fontMetrics().height();
this->QHeaderView::setFont( aFont );
setFixedHeight( fontMetrics().height() + bufferSize );
}
This works like I was hoping it would - the header's height changes as the font height changes. The problem I'm encountering now is that the rest of the QTableView doesn't seem to recognize the header's height change. As a result, the first rows of the table are hidden by the header if the header's height increases.

Is there some signal the header should be emitting when it changes height? How can I get the grid to resize properly when the header size changes?

Jimmy

wysota
19th December 2006, 21:56
Reimplement sizeHint() for the header.

Jimmy2775
19th December 2006, 23:43
Yes that works. Thanks.

Why are there functions like setFixedSize and setGeometry when the only one that seems to matter is sizeHint()?

wysota
19th December 2006, 23:51
sizeHint is used when widget is inside a layout to indicate what size is preferred by the widget to display itself correctly. setGeometry actually resizes the widget, but when the widget is inside a layout, the layout will resize the widget back to the size calculated for it by the layout according to the sizeHint and a few other parameters. setFixedSize equals to two other calls - setMinimumSize(w,h); setMaximumSize(w,h) - it forces a constant size by fixing the range of allowed sizes. The layout should respect that setting as well as minimum and maximum sizes are taken into consideration by the layout when calculating widget's size and position.

Jimmy2775
20th December 2006, 00:14
That is an excellent explanation - thanks.