Once created, a QTableWidget gets some default size. I add rows to it and with the proper layouts, size policies and setStretchLastSection(true) the horizontal size is OK, filling all the available space and changing when the view gets resized. With many rows, the vertical size is also OK. But, with only a few rows, empty space remains at the bottom. How do I convince the QTableWidget to shrink vertically to the size of the data? Calling adjustSize() at various stages appears to do precisely nothing.
That is the only problem I originally had, and based on the answer I might be able to figure out a solution to my current problem:
I have several several custom widgets with a QTableWidget as a member variable, in a layout. Each table used to have its own scroll bars, but I decided I had to make the tables stay at a fixed height (matching the amount of data) and have the entire view scroll instead. This is proving... difficult. The view does scroll OK, but the tables inside it remain at the default size, in both directions now, no matter what I do. Well, I was able to enlarge them using setMinimumWidth(600), but a hardcoded size is not acceptable.
Seriously, I'm going nuts with all these nested layouts:
view layout, also has a layout for command buttons in addition to data layout
-> data layout, which is set to an empty QWidget, which is set to a QScrollArea, which is set to view layout
--> header layout for QLabel header and custom widget
---> table layout in the custom widget that finally contains the QTableWidget. Which seems to be depressed from being on the bottom of the layout stack and therefore not willing to expand to its full potential.
Please advice. Anybody willing to take a look at long-ish sample code?
The header layout, label and widget are all actually member variables in a struct that's supposed to represent a header+table combo, which isn't necessarily good design, but I tried removing it and that didn't help.
Bookmarks