PDA

View Full Version : autoexpanding QTableView columns



ucntcme
8th January 2008, 21:53
I would like my QTableView columns to expand (equally preferably) to fill the width they have available (this one is inside a QStackedWidget but that shouldn't matter I'd think - providing context.).

I can have columns resize to contests, but that isn't the issue. I could also set the size manually but well that just sucks and doesn't expand if/when the user makes the window wider.

A "non-full-width table" looks cheap IMO, and could confuse some of the users :rolleyes: (remember, we don't all get to choose our users' wits level ;) )

wysota
8th January 2008, 23:54
Set the resize mode of the header to "Stretch".

ucntcme
9th January 2008, 00:37
Thanks. Wish that was an option in Designer. ;)

Gopala Krishna
10th March 2008, 15:58
Set the resize mode of the header to "Stretch".

Ok. Now how do i set a descent size for all the columns without those ellipses initially such that scrollbars are avoided to the best extent ?

Calling resizeColumnsToContents() and also setting wordWrap to false doesn't help me set initial size :(

Screen shot 1 : The actual result.
Screen shot 2 : The expected result.

wysota
10th March 2008, 18:06
I don't think I understand what you mean. Would you care to explain?

Gopala Krishna
11th March 2008, 01:41
What i mean to say is,
Now i am getting the dialog in 1st screen shot in which the last column text isn't shown fully (ellipses are shown in the end)

What i want to achieve is the dialog in 2nd screen shot, in which the viewport of the tableview is of proper size to fit all columns without ellipses.
How do i do that ? Calling resizeColumnsToContents still results in the first screen shot.

wysota
11th March 2008, 09:28
You mean you want the dialog to expand itself to fit its contents? It's not an easy thing to do as the table or its header doesn't report a minimum width that would fit its contents. You have to calculate the width yourself and that's the hardest part.

You may also use QHeaderView::setStretchLastColumn(false) and optionally change the resizeMode of columns to ReizeToContents. You'll get scrollbars though...