Qt Creator expanding Layout "working area" issue - qt

I followed the steps here: Auto-expanding layout with Qt-Designer
I now have the issue that the "dotted area" is not expanding with the window

Set layout for your window (right click on window and select layout in bottom of context menu).

I had to click on the central widget and change the maximum size there

Related

How to add menu bar and toolbar into the qdialog

Exists any solution how to add menu or tool bar into the QWidget dialog?
I making something like ERP system. There are many windowses opening from others windowses. It's important that one (parent) window waiting for choices in children window. And in the chidren window sometimes I need toolbars and menu bars...
Problem is, that
new child QMainWindow have no exec() function. It cause that parent window no waiting for finishing choices in the child.
new child QDialog have no menu or toll bar.
Exists any solution (without events)? Solution how to add menu or tool bar to QDialog, or solution how to open new qmainwindow with waiting mode myMainWindow->exec()?
Ok. I find solution.
I used QDialog. Menu or tab bar will be added as:
anylayout->addWidget(tabbar); or anylayout->setMenuBar(tabbar);
Thx for answer by Chris Kawa:
The difference is that setMenuBar places the widget outside of the layout content, so the top margin of the layout is below the bar . With addWidget the bar is added as a layout content, so it respects the margins (controlled by setContentsMargins).
For menus and toolbars we usually want them to stick to edges without a gap, so the setMenuBar method is more appropriate for it.

How to restrict growth (size) of layout in Qt Designer?

When I maximize my window, I want to restrict a vertical layout (and the entire row below it also) so that it has a specific size (lets say a width of 200). How can I achieve this? Below is what I get now. The buttons are stretched too far. I want them to keep a width of 200.
To stop the buttons stretching, use the following steps in Qt Designer:
click on scrollArea in the Object Inspector
click on Break Layout on the toolbar
click on scrollArea in the Object Inspector
click on Lay Out in a Grid on the toolbar
click on scrollAreaWidgetContents in the Object Inspector
scroll down to the bottom of the Property Editor
change layoutColumnStretch to 0,1
These steps should remove an empty column from the scroll-area grid-layout, and make the second column stretch to take up the available space when the window is resized.
You just need to restrict the maximum width of all widgets (in this case the buttons) within the layouts of this grid column to the expected size, else they'll just keep expanding. You may also have to fiddle the horizontal size policy; I seem to remember that buttons were a bit tricky in this regard (or was that the height?), but can't test it right now.
The layout size contraint you tried only applies to the layout's direct parent widget, if it has one, which isn't the case for the vertical layouts here.

How to set display ratio between widgets in Qt layout?

In a tab page I do have one tree view widget and one tab widget inside the vertical layout, I want to set 60% of screen space to tree view and 40% to tab widget, always. How can I do this in Qt Designer ?
Platform: Qt Creator 2.4.1 / Win 7.
If you click the parent widget and scroll down its properties, you will find the properties of its layout at the very bottom.
You can set the layoutRowStretch and layoutColumnStretch properties there.
In case of a vertical layout, you could for example set "60,40" (or "6,4" or "3,2") as value for the layoutRowStretch property.
This will mean the factor of the first row to the second row will be 60:40 = 3:2

QT - Place Buttons on Bottom Right

I am trying to place a set of buttons so that they are anchored to the bottom right of the screen. My problem is that whenever I resize the screen, the buttons are not anchored to the bottom right, but stay in its current position.
I have placed two Push Buttons inside a Horizontal Layout. I then placed this layout inside a Grid Layout, which contains a Horizontal and Vertical Spacer. I have modified the Grid Layout layoutSize property to SetMaximumSize.
What am I doing incorrectly, so that I can get my buttons to be anchored to the bottom right?
You have almost everything just right here, but you probably overlooked something that is really easy to miss when you first start using Qt Designer.
Your grid layout is sitting inside your widget with a fixed size and position. It too needs to be managed by a layout. If you take a look at the Object Inspector on the top right (that contains your hierarchy) you will probably see your top level widget with a red icon. This indicates that it contains no layout. You have two options to fix this...
Have your existing grid layout placed into another main layout (like a vertical layout). You would simply right click on your top level widget in the Object Inspector -> Lay Out -> [Choose a main layout type].
Have your grid be the main layout. To do this you would need to remove the grid layout and have your child items arranged exactly how you have them in that picture. Then follow the previous option, right clicking on the top level widget (or the blank background) and choose Lay out -> Grid. This will pop your widgets into a Grid at a best visual fit (which you can then fix if needed), and your grid will be the top level layout.
That grid layout will make placing other widgets quite hard. Try this instead:
Add (from left to right) horizontal spacer and the two buttons.
Multiselect them all.
Select "Lay Out Horizontally" (Ctrl-H) from the Qt Designer's (or Qt Creator's) top toolbar (not from the widget box in the left!).
Add vertical spacer on top of the previous widgets.
Select the main window by clicking it (none of the added widgets are now selected).
Select "Lay Out Vertically" (Ctrl-L) from the top toolbar.
Done.
It seems that you're doing it correctly. Just forgot to apply a layout to your central widget, right? The Grid layout should be arranged in your central widget. The more convenient way is to remove grid layout widget and lay out the central widget in a grid ;-)

Set widget in center in QDesigner

Is it possible to set widget in center of dialog or windows in QDesigner, say I have a widget contain 3 line edits and labels and I want to set this widget in center of window.
In latest Qt Designer, right-click a widget in the Object Inspector and choose your preference under Layout Alignment.
It should be quite simple:
Insert horizontal spacer
Set Horizontal layout
Insert Vertical layout
Insert another horizontal spacer
Add Vertical spacer to Horizontal spacer (drag to widget tree)
Add your widgets .... labels, textedits
Add another vertical sapcer to Horizontal space
Works in my QtCreator, should also in Your Designer :)
Good luck.
Add a layout to your windows and add the widgets in the layout. Then you can set the position policy in the properties panel of the layout.

Resources