Unsolved Can't configure properly my layouts
-
I created with QT designer two widgets.
This one is simple (OperatorPanel), it uses an horizontal layout and a fixed size widget containing itself some sub widgets:
This other one is most sofisticated (CurveEditorWidget). It uses a vertical layout.
In this layout, there is :- a scrollarea that should expand in both directions
- an horizontal layout : it contains many sub widgets. All these widgets' height is fixed and their's width is also fixed except for the currentPointFunction_lineEdit widget. Then, this is the only one that should expand horizontally.
Here is the view in the QT Designer:
If I resize it in the QT designer, everything seems nice.
Now, I add in the OperatorPanel constructor a new CurveEditorWidget using:
curveEditor_widget = new CurveEditorWidget(); ui.horizontalLayout->addWidget(curveEditor_widget, 0, Qt::AlignLeft); curveEditor_widget->show();
Then, I add an OperatorPanel to a main window and I resize it using :
int width = this->width() - 5; myOperatorPanel->setFixedWidth(width);
But it always take the minimum size the widget can use:
Note that the widget is added dynamically at a moment when the "width" variable has the expected value (window is painted).
I certainly didn't try everything because I think there is a solution, but after many tries when configuring my layouts and widgets size policy, I can't realize the expected result and expand the complete widget horizontally.
I'm sure that if I understand how to perform this, I will work harder on my main window to also use layouts (actually I'm placing in it widgets using absolute positions and setting fixed width on them).
Anyone can help ?
Thank you very much.
-
Hi and welcome to devnet forum
Looks like the hosting widget where you are placing the 2 widget does not have a layout assigned.
How do you create the hosting widget?
-
Hi and thank you for your help.
The CurveEditorWidget widget is added to the OperatorPanel widget, which uses an horizontal layout (can see it in the inspector of QT Designer).
Then, the OperatorPanel widget is added to a main window and its size is changed through the "setFixedWidth" function.
-
From the attached picture one cannot see what is around, but typically you can select the MainWindow with its whole content in designer and apply a layout and you are done.
When you do this code, you have to add a layout and fit both widgets into it.
From personal experience I recommend playing around in Qt designer (add a form in Qt creator) a bit. When you are satisfied with the outcome, you can moc the result and checkout the generated code.
-
@PP_RhuM
Maybe I'm misunderstanding. If you want your/one/a widget to expand to fit its parent horizontally, have you ensured your widget has something likesetSizePolicy(QSizePolicy::MinimumExpanding, ...)
(http://doc.qt.io/qt-5/qwidget.html#setSizePolicy-1)? You don't care about fixed sizes or resizing or when you add it to its container then. -
I Changed a little thing: I added all my controls (in the bottom of the CurveEditorWidget) in a simple widget container (see in the inspector) :
In the structure, here are size policy (H / V):
- CurveEditorWidget = MinimumExpanding / Prefered
- curve_scrollArea = Expanding / Expanding
- optionsContainer_widget = MinimumExpanding / Prefered
- currentPointFunction_lineEdit = MinimumExpanding / Fixed
- All other widgets under optionsContainer_widget = Fixed / Fixed
For the OperatorPanel widget:
- OperatorPanel = MinimumExpanding / Prefered
- pitchDials_widget = Maximum / Fixed
- All other widgets under pitchDials_widget = Fixed / Fixed
I change the width of the instance of the OperatorPanel added dynamically to the main window. It's not placed in a layout, it's placed in the main window itself and positionned in an absolute place.
Should i add another container to embed the operator panel widget like this ?
QWidget *container = new QWidget(this); QHBoxLayout *container_hLayout = new QHBoxLayout(container); container_hLayout->addWidget(operatorPanel); container->setFixedWidth(this->width() - 5);
It doesn't make really sense because the OperatorPanel widget should be sizable with size I want..