Sign up for the KDAB Newsletter
Stay on top of the latest news, publications, events and more.
Go to Sign-up
Find what you need - explore our website and developer resources
17 March 2022
Unless you have never used QTableView, I'm sure you at some point in your life have cursed it because you couldn't exactly figure out how to do one of the following things
* ensure it didn't show a lot of blank space next to the columns
* made it stretch a specific column
* made it fit the columns to the content
* ... and still made it possible to resize the content of those columns
* found a way to resize it to show the content without scrollbars.
* avoid that it spills a lot of vertical space!
OK, at least I've had all of the above, so I created a simple example showing how to solve all those problems.
0:00 Intro
0:40 The default setup of the test application
1:49 Using Gammaray to check what the white space is
3:00 Stretching last column and last row
4:16 Stretching other columns
6:05 Stretching rows to their size hint
7:20 Initializing columns to their minimum size, while still allowing them to be resized
8:42 setResizeContentsPrecision
10:34 Make the tableview take the exact size it needs to display all its content
Series on Gammaray: https://www.youtube.com/playlist?list=PL6CJYn40gN6itybeSJb5FvRWOxVW5PCUX
The example code showcased in this video is available here: https://github.com/KDAB/kdabtv/tree/master/Qt-Widgets-and-more/StretchingTableViews
All Qt Widgets and more videos:
https://www.youtube.com/playlist?list=PL6CJYn40gN6gf-G-o6syFwGrtq3kItEqI