PDA

View Full Version : QTableView row heights



Brandybuck
6th April 2006, 06:47
QTableViews have much thicker rows/cells than Qt3 QTables did. They appear to have about a 6 pixel padding. This is wasting too much screen real estate, and in my opinion looks unprofessional.

What is the best way to resize the rows? I was using resizeRowsToContents(), but it's not quite right. What I want is something on the order of the row heights in Designer's property editor. I'm not understanding the Designer code and so I can't find how they do it. The default height (with my font) is 30 pixels. Using resizeRowsToContents I get 27 pixels. Designer has 21 pixels. See the difference?

Any hints?

munna
6th April 2006, 07:36
void QTableView::setRowHeight ( int row, int height )
Sets the height of the given row to be height.
This function was introduced in Qt 4.1.

Brandybuck
6th April 2006, 08:06
There's no way to adjust the height automatically based on the current font? Otherwise I have to calculate the font sizes myself. I can certainly do this, but it seems to me that Qt should be doing this kind of low level stuff for me. After all, I don't have to do it for any other widget.

Is this really how Designer does it?

wysota
6th April 2006, 09:09
You may use a custom delegate with different padding values.

Brandybuck
7th April 2006, 04:20
I'm not sure exactly what you mean. I looked in QItemDelegate source, and I see that there is a hardcoded text margin of 3. Is this what you mean? It is the only thing I can find that could be considered "padding". Will I have to rewrite all of QItemDelegate's display code in order to resize some rows? In such a case I might as well inherit from QAbstractItemDelegate instead!

I am aghast that something that should be simple is so difficult. Am I just being stupid?

Brandybuck
7th April 2006, 05:29
Solved! It turns out that even though the vertical header is hidden, it is still being used to calculate the minimum row height. The only way I can figure to change this is by tweaking the font size for the header. Since it's hidden the smaller font won't be seen. That's probably not the best solution, but it works.

wysota
7th April 2006, 10:10
I'm not sure exactly what you mean. I looked in QItemDelegate source, and I see that there is a hardcoded text margin of 3. Is this what you mean? It is the only thing I can find that could be considered "padding". Will I have to rewrite all of QItemDelegate's display code in order to resize some rows? In such a case I might as well inherit from QAbstractItemDelegate instead!

I am aghast that something that should be simple is so difficult. Am I just being stupid?

Item size is determined by the size returned by delegate's sizeHint method, which is in turn based on getting data from SizeHintRole of the item, so you can either reimplement sizeHint(), set data for SizeHintRole of the items (or the whole model) or reimplement the delegate's painting routine (note that this will not alter the cell size, only its content).

Brandybuck
7th April 2006, 21:42
Item size is determined by the size returned by delegate's sizeHint method.
I eventually discovered that, but it wasn't working for me. My problem was that the QHeaderView was placing a minimum size on the row heights, so that while I could make the rows bigger, I could not make them smaller. See my solution above.

ghorwin
7th November 2006, 03:08
I still have a problem with my row heights. I cannot make the font of my headers smaller, because I use them. And the size hint I set in my costum item delegate only works for the actual table cells, but not for the headers.

Does anyone know how I can set the row heights for the headers?

Bye,
Andreas