PDA

View Full Version : QTableWidget column width and resizing



shooogun
14th March 2008, 06:20
I've searched the classes documentation, but couldn't find anything about this;

I've got my main window which can be resized, and I'm trying to work out how to get the columns in my table to maintain the width proportion while resizing, i.e. column 1 will have 20% of the total table width, column 2 50 % etc. Is there a way to do this?

Also, I'm trying to get the last column to maintain its width no matter the size of the main window. is there way to restrict the column width to the last column, while giving the other columns the ability to stretch?

setResizeMode appears to set resizing mode to the whole table, not individual columns.

cheers

wysota
14th March 2008, 09:45
There are two variants of QHeaderView::setResizeMode() - one is working on the whole header and the other on a single section.

shooogun
16th March 2008, 23:31
Yeah, I was looking at that, but couldn't get the sections to behave the way I wanted. I can add the lines

self.table.setColumnWidth(0,400)
self.table.setColumnWidth(1,200)
self.table.setColumnWidth(2,200)
self.table.setColumnWidth(3,50)

header.setResizeMode(3, QHeaderView.Fixed)

and that will fix the width of the last column, but when I resize the window, the columns don't move. I tried adding these lines

header.setResizeMode(0, QHeaderView.Stretch)
header.setResizeMode(1, QHeaderView.Stretch)
header.setResizeMode(2, QHeaderView.Stretch)

but that causes erratic behavior in the column width when the window is resized, and also negates the column width that I set previously.

It would be awesome if I could make the first 3 columns stretch, while the 4th column is fixed and is always on the tables' right side. Thats what I'm trying to achieve. Any more advice?