View Full Version : Layout manager for TableView

20th October 2009, 19:56
I have a tableview with several columns. I would like the size of the columns in the table to adjust depending on the window size, but I would also like to apply sizing hints to the layout manager so the columns get resized appropriately. For example, apply 1/8th of the space to column 2, 3/8th's of the space to column 1, and the rest to column 3.

Is this possible? I've seen the "resize based on contents" but this isn't what I'm after, and seem to disable user control of the column sizes.

20th October 2009, 20:06
I think you should subclass from QTableView an reimplement the resizeEvent (http://doc.trolltech.com/4.5/qabstractitemview.html#resizeEvent).

20th October 2009, 20:30
You don't think reimplementing sizeHintForColumn is enough? (Not sure exactly what it does, hence the question, I'm just guessing here from information in QtAssistant)

EDIT: resizeEvent seems to work fine, and the values it gives are perfect. I usually end up calling all kinds of strange functions to work out invisible borders, whether or not the scroll bar needs to be there and if so work out the size of that, etc, but not in Qt. I like it :-) The fact that you can subclass a component in the designer is a real plus too, I've not seen that in any other environment.