View Full Version : Minimise row height in Tables

3rd May 2009, 16:34
I am using both QTableWidget and QTableView Classes.

Now these widgets take much more space in height than a listview with the same data. Now I want to minimize the row height for all rows to the minimum possible value.

I have seen the function
void setRowHeight ( int row, int height ) but that has to be applied to all rows and is not available in QTableWidget.

Any hints appreciated.


3rd May 2009, 17:30
Use void QTableView::resizeRowToContents( int row ) instead (by the way: setRowHeight() is inherited by QTableWidget ;)).

Yesterday I had the same problem. I didn't know what height to give setRowHeight() so I simply tried resizeRowToContents(). I hoped to get a minimized row height and a width that would show all the text in my table.
The latter didn't happen, but the row height was minimized *juhu*.

3rd May 2009, 17:44
To resize row in a table, try :
table->verticalHeader ()->setDefaultSectionSize(height);

Refer : QTableView::verticalHeader and QHeaderView::setDefaultSectionSize

3rd May 2009, 18:35
In addition with QHeaderView::minimumSectionSize() this might do the job.

3rd May 2009, 18:39
Setting minimum will not reduce the row height. It will just tell that height shud be ATLEAST minimum...

3rd May 2009, 18:44
I thought of using the return value of minimumSectionSize() as argument of setDefaultSectionSize().

3rd May 2009, 18:59


works perfect in a QTableView Class

3rd May 2009, 22:08
A QTreeWidget can have multiple rows and columns and has a smaller default row-to-row distance than a QTableWidget.