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

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.

Related

QDockWidget ignores layouts and size policy from the form

I'm subclassing from QDockWidget and I want my class to use form. I've made a form based on QWidget and included Ui class in my QDockWidget-based class. But the build result differs from the Qt Designer preview, because QDockWidget completely ignores all the preset size policies and layouts from the form, so most of the content just doesn't show up and the rest has nothing in common with the preset settings. My class looks fine if I subclass from QMainWindow or QWidget. How to use forms for QDockWidget?
This question could do with some sample code from the .ui files to clarify the question.
However one possible cause of this is that Qt form layouts QFormLayout by default don't expand to fill their parent widget. If the QFormLayout is embedded another top level layout such as a grid layout the contents of the QFormLayout will then expand to fill the available space.

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

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

How to prevent QTableWidget from occupying the whole window in a QHBoxLayout?

In my Qt program, I programmatically generate a modal QDialog. I want to show two widgets in this dialog window: A custom widget showing a camera output and a QTableWidget, showing the pixel coordinates of the corners found in the camera image. I generate a QHBoxLayout and add my custom widget and the QTableWidget into it. Then I set this QHBoxLayout as the Layout of the QDialog window. What I want to achieve is to share the available space in the QDialog's window area equally between my custom QWidget and the QTableWidget, horizontally, by using a QHBoxLayout. But I always end up with QTableWidget occupying the whole QDialog area, by overlapping my custom widget. How can I instruct these two widgets to exactly share the QDialog area?? Note that I first add my custom widget and then the QTableWidget into the QHBoxLayout.
Make sure on your custom widget you've specified a minimumSizeHint and a sizeHint, this instructs the QLayout manager that the widget requires a specific space. To have them split equally you'll be best off detecting the size of the QDialog and then specifying the width for both by removing the boundary sizes (spacing between widgets + space to QDialog edge) and dividing it up.

Resizing a QDialog after adding components to a child widget

I'm a bit new to QT but have to work on existing code. Here's the case:
I have a class extending QDialog. the constructor sets a QGridLayout then adding three other widgets to it. One of the widgets is a QScrollArea containing a QGroupBox. this QGroupBox has a QVBoxLayout and there I'm adding a list of widgets at runtime. The size of the scroll area should grow until a given limit is reached before showing the scrollbars so that they are only used when the dialog would grow too high. I've found that the sizeHint of the outer layout doesn't update when the sizeHint of the scroll area updates. How can I refresh this, or is there a better way to resize the parent dialog?
What about using widgetResizable property of QScrollArea? It should try to resize view to avoid using scorllbars.

Is there a way to emulate a QGroupVBoxLayout?

I am using Qt designer and I know how to use a QVBoxLayout and QGroupBox but it seems there is no such thing as a QGroupVBoxLayout. So I have to put a QVBoxLayout inside of a QGroupBox but if I modify the dimensions of one I have to do the same to the other. Is there a way to make them change dimensions together directly from QT designer?
Add a QGroupBox to the form
Add widgets to the QGroupBox at positions where you would expected to be when the layout is applied (it doesn't have to be precise)
Select the QGroupBox and click the "Lay Out Vertically" toolbar button (the one with three blue vertical bars)

Resources