PDA

View Full Version : Widget resizing issues



SKolaMunn
15th September 2011, 15:27
This seems to be a basic problem but I can't figure it out. I have a QMainWindow with a QTabWidget. Throughout my application I add different tabs to my main window, these tabs sometimes include large items which don't fit in the current tab space.

Here are my specific issues:
1) When adding a tab that requires a minimum amount of space to view all its child widgets, how can I grow my main window to fit this tab properly.
2) When resizing my main window, I'd like it to not shrink past the minimum size my tab requires, when growing my main window, I'd like my tab to grow with it. This seems like basic functionality but I can't seem to get it to work!

What I've tried is using a QScrollArea, so that if the main window does shrink too much, scroll bars will appear and my tab widget is still "in tact" (all buttons are readable, etc., but I have to scroll to see everything). This isn't behaving properly though because as I resize my main window, my scroll area sort of "resets" its minimum size to its last size, so if I make it really big (larger than needed), then shrink it, the scrollbars appear right away (as opposed to shrinking my tab until its minimum size and then adding scroll bars when needed). I do set my scroll bar policies to Qt::ScrollBarAsNeeded. I also tried with and without setSizeConstraint(QLayout::SetMinimumSize) on my main layout that my scroll area is inside and I've tried with and without setSizePolicy(QSizePolicy::MinimumExpanding,QSizeP olicy::MinimumExpanding); on the widget that my scroll area "sets". I'm now thinking a scroll area is not the way to go (and I just need to make sure my main window is big enough, but isn't there always a possibility that the computer screen will just be too small to show all the widgets at once?)

Without the scroll area, everything behaves much better but my custom widget that I am displaying inside my tab doesn't seem to have a minimum any more. You can resize the main window so small that the buttons and combo boxes just overlap on top of eachother and squish together really small. (Resizing larger does make the widget grow as desired)

I'm now thinking my problem is just that I need to set the minimum size to exact values, but what if I don't know the dimensions? I just want it to fit all its child widgets (which are arranged in layouts).

What am I missing?:confused:

I did leave out one thing. I put a "resized" signal in my parent widget and connected that to a slot in my custom widget that i am displaying in my tab that resizes my child widget to its allotted space in the parent widget. Without this the second method I tried (without the scroll area) doesn't resize the widget in the tab at all, it just always stays the size its first displayed. I did try everything with and without this slot. Either way the widget shrinks too much when the user shrinks the main window, which I'd just like the user to not be able to shrink past the tab widget's minimum size! (or do allow that but add scroll bars afterwards and ONLY after its shrunken past the minimum, when i tried the scroll bars they were always added when shrinking the window (no matter how large the window was).

Update: If I do hardcode the minimum size to values that I guessed at, the buttons don't overlap when the window shrinks too much but the widget gets cut off, so you can only see the portion in its top left corner. Why can't I make my main window not shrink past the size needed for its child? Is it because this widget is inside a QTabWidget?