E
E
Egorithm2020-06-07 17:43:20
Qt
Egorithm, 2020-06-07 17:43:20

Qt. How to push the contents of a QVBoxLayout to the top?

I have QRadioButtons inside QVBoxLayout, and it is not known in advance how many there will be, because it depends on how the file is parsed. I wanted to add a QSpacerItem to the layout, but there you need to specify the height and width in the constructor, setFixedHeight for QRadioButtons also does not work, they still stretch in height to the entire widget. How to be?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
J
Jacob E, 2020-06-07
@Zifix

0. Read any Qt tutorial, experiment with QtDesigner. Save a lot of time on such elementary questions.
1. Without code, it is impossible to say where the error is, why your buttons with such a modifier are stretched.
2. Read the documentation, in this case how to use QSpacerItem, and what are the values ​​in the constructor. Or Google ask before asking a question.
3. https://doc.qt.io/archives/qt-4.8/qboxlayout.html#...

V
Vladimir, 2020-06-11
@radianto

The easiest way to place one grid inside another and add a spacer

auto layout = new QVBoxLayout(parentWidget);
auto radioLayout = new QVBoxLayout();
radioLayout->addWidget(radio1 = new QRadioButton());
...
layout->addLayout(radioLayout);
layout->addStretch();

Moreover, it will be possible to add to radioLayout after the form is created

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question