PDA

View Full Version : resize qtableview



jackajack01
19th September 2012, 14:07
hello

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.

thanks

8228

d_stranz
20th September 2012, 01: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.

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


view->horizontalHeader()->setStretchLastSection(true);

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

d_stranz
20th September 2012, 16: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.

ChrisW67
20th September 2012, 22: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.