Qt designer: How to add widget to a layout in the designer when the layout appears infinitely thin? - qt

I am using Qt Designer, and I would like to move a couple of top-level widgets into a horizontal layout.
I have dragged a "Horizontal Layout" object into the form. I am now attempting to drag the desired widgets into the layout.
Unfortunately, the new Horizontal Layout widget is infinitely thin:
... and I cannot drag my "Import Progress" label widget or my progress bar widget into the new horizontal layout widget.
Note that when I attempt to drag the desired widgets over the new horizontal layout widget, Qt Designer does not do anything useful for me in terms of expanding the drop region to make the horizontal widget available as a drop target. So I'm stuck.
How do I add widgets to an infinitely-thin layout widget in Qt Designer?

Select the layout, and then drop the widget onto the corresponding selected item in the Object Inspector pane. If you find it tricky to select the layout on the actual form, you can also select it via the Object Inspector pane.

One way (that I usually do as a workaround for not having to show the structure panel) is to select the layout, setting the top or bottom margins to any value (10, whatever) and then dragging the component into the layout. Yeah, that is just for the pure pleasure of dropping the component in the layout, i know, but is a way.

My small trick:
Select layout
Change temporary "layoutTopMargin"
Drop into layout required widgets
Restore layoutTopMargin to default 0

Related

Why won't QGroupBox widgets dynamically resize with rest of window?

I have a QMainWindow with the widgets laid out in a grid. They all resize proportionally when the window resizes as expected, except for the widgets placed inside a QGroupBox. The QGroupBox itself resizes, but the widgets inside just stay on the same place. If I apply a lay out on the QGroupBox, the widgets loose their original positions. Note that I'm using the .ui file with PyQt4. You can get the file here.
And this is what happens:
From Qt documentation on QGroupBox:
QGroupBox doesn't automatically lay out the child widgets (which are
often QCheckBoxes or QRadioButtons but can be any widgets).
There is an example showing how to setup a layout for a QGroupBox (which is the same a setting up a layout for any QWidget based object meant to store other objects, like QFrame for instance).
You must create a layout, call QGroupBox::setLayout and then add widgets to the layout. If you use QtCreator, right-click the QGroupBox and select the layout you want to use for it from the context menu.

Widget or layout to fill parent

What I'm trying to accomplish is a very simple and straight forward need, or I thought, but for the life of me, I can't seem to find a way to do it.
In my qt application I want to be able to make a widget or a layout fill the entire space of the parent widget.
For example, let's say I want to have a label with a fixed height and beneath it a stacked widget which occupies the rest of the height of the window.
Here's what I do in the qt-creator designer:
drag a label to the form
drag a stacked widget to the form
select both of them and then right click > lay out > lay out vertically
select the verticalLayout object and in the layoutStretch property have 0,1
Now, how do I make the verticalLayout occupy all of the width/height of the centralWidget?
Nothing seems to work for me.
Thanks.
You've merely put two widgets in a layout, but you also need a layout on their parent widget - on the form. Here's what you should do instead:
Drag any number of widgets to the parent widget (the form). Arrange them roughly the way you want them to be once laid out.
Right click on the form. Select "Lay out >" submenu.
Choose the desired layout from the menu: horizontal, vertical, grid, etc.

expanding widgets inside a Qtabwidget

Why does the widgets inside a QTabWidget don't resize?
All my widgets resize except for the ones inside the tabs, even the tabs resize, but not the items inside it.
Is this because of the type of layout as I show in the figure?
I can's assign a layout to it. this is before and after maximizing the window.
Why can't you assign a layout to it? You just have to give each tab a layout. Drag your widget into the tab. Select the tab, not the widget, click on one of the layouts in the top row of the designer. Your widget will fill the whole tab and resize nicely.

How to make a QTextEdit fill its parent dialog?

I've been using Qt for some times, but I'm quite new to layouts. I would like to create a dialog with a QTextEdit inside, and the QTextEdit would resize to fill the whole dialog. How can I use layouts to do that? Or is there some other technique that I'm missing?
I have tried adding a layout to the dialog, then put the QTextEdit inside. However, I cannot find any property to make the layout fit the whole dialog.
After adding the text edit to your form, right click on the form and you will see a "Lay out" menu item at the bottom of the context menu, select that and then the layout type you want to use. The designer will create a top level layout of that type for your form and the text edit should now expand to fill the form.

Qt widget com problem

I have a Rectangle widget, and a resize box widget, and a text edit widget. How can I compose them without using layouts ? I want all of them as a single widget.
The documentation for how to do a manual layout is in Qt Layout Management here.
Are you sure you can't use one of the standard layouts? You can make a custom widget with three children positioned inside using a layout (or layouts) and your new custom widget will still be just a single widget.

Resources