[solved] Getting center area of screen to stretch when window is resized
-
I have a layout that is basically a title, center area, and footer. When the screen is resized I want the center area to resize. I've currently designed the GUI in QtDesigner and I'm not using any code to "adjust" the GUI widgets.
The GUI (somewhat simplified) is like this:
@--------------------------------------------------
| TITLE || Table | Tabs |
| | |
| | |
| | || Buttons |
-------------------------------------------------@The table and tabs are in a horizontal splitter. When the screen is resized, I would like the center area (the horiztonal splitter) to grow but the title area and buttons to remain the same size and anchored to the top and the bottom of the screen (respectively).
Is this something that I can do in the designer? Or will I need to use code?
NOTE: I tried to use the designer and add layouts but they basically caused my "center area" to shrink and ultimately I backing away from that approach.
-
I got it working based on your question, but to answer the question. No nothing (in code) yet, all is in QtDesigner.
To make this easier to solve. I created a trivial sample. GUI window has ComboBox,and two TextEdit widgets. I put them in a VerticalLayout.
The default behavior is for designer to not stretch (grow) the combobox, but to stretch both TextEdit widgets so they fill the space/size of the QVBoxLayout.
On the "centralWidget" (aka MainWindow) I add a horizontalLayout (without this nothing resizes.... why is that?)
I use the following code so that the first text area will resize but the other will remain fixed and this seems to work.
--
@
ui->textEdit->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
ui->textEdit_2->setSizePolicy( QSizePolicy::Fixed , QSizePolicy::Fixed );@
So thanks for your help. Now is there any way to get the designer to display things the same way as they appear when I run?
The 2nd text box is not stretched (anymore) even though in the designer it is.
Thanks again.
-
You can setup layouts in designer
Nothing resizes because if you don't use layout managers, it's up to you to update the size and position of your widgets inside your widgets.
-
Through trial and error I found the reason the center area was not expanding was due to the property:
QTableView, sizePolicy, Vertical Policy = Preferred
When I changed it to "Expanding" the QtEditor displayed the center area as expanded.
I also learned how to set the sizePolicy in QtEditor instead of via code. The trick was to double-click on the property NAME (not the property value). When I double-clicked on the property "sizePolicy", then I could change Vertical Policy to Expanding.
Thanks for your help!