PDA

View Full Version : Minimise row height in Tables



pospiech
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.

Matthias

Boron
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*.

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

Refer : QTableView::verticalHeader and QHeaderView::setDefaultSectionSize

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

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

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

pospiech
3rd May 2009, 18:59
Using


tableViewPowerDegree->verticalHeader()->setDefaultSectionSize(tableViewPowerDegree->verticalHeader()->minimumSectionSize());

works perfect in a QTableView Class

drhex
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.