View Full Version : resize qtableview

19th September 2012, 15:07

I have several qdockwidget and within these a qtableview, as seen in the attached picture, my problem is I want the tables are the same size of the dock.

I tried to do this and it does not work:

table-> resize (dock-> size());

maybe is a silly question and should go in the section of rookies do not know, but I could not really find a solution, I hope you can help me.



20th September 2012, 02:53
The tables in your screen shot are the same size as the dock widgets that contain them. I think what you want is for the cells in the table to expand to the full width of the table, right? To do that you need to get the columnWidth() of each column in your table, add them, then set the width of the last column to the difference between the sum and the table width.

20th September 2012, 04:35
You can set the last section to automatically stretch to the right using the horizontal QHeaderView, something like:


You can use the QHeaderView::setResizeMode() make other columns stretch.

20th September 2012, 17:39
Thanks, ChrisW67 - I knew that method was around somewhere and spent some time looking for it, but didn't think to check in the QHeaderView docs. That's definitely the way to do it.

20th September 2012, 23:43
I had to hunt for it also. I think that placing it in QHeaderView is counter-intuitive. It becomes even more so when you consider that there may not even be a visible header, yet it controls the width of the table columns on resize.