P
P
Paul2016-12-22 18:25:07
Programming
Paul, 2016-12-22 18:25:07

How to add a scrollbar to a layout where LineEdits are added in QT?

Hello! There was a seemingly simple task, but it is impossible to implement.
The screenshot shows an example of a part of the interface that I made.
03fa12ece137451db0fc85304dc1d54c.PNG
The bottom line is that when you click on "add powers" in the layout, which is located below, N LineEdits should be created for entering numerical values. I implemented this in a loop, the main logic of which is given below:

ui->scrollArea->setLayout(ui->verticalLayout);
int height = INITIAL_VALUE;
for (int i = 0; i < count; i++) {
    ui->verticalLayout->addWidget(new QLineEdit());
    height += 50;
    ui->scrollArea->setGeometry(15, 290, 160, height);
}

As you can see, I placed the Layout inside the scrollArea hoping for scrollbars, but they are not added. Therefore, I made a crooked implementation in the form of resizing the scrollArea, but it works until the number of required LineEdito-in reaches a large value.
In general, I would like to create a Layout of a fixed size and add LineEdits to it, and in the case when the LineEdits do not fit in the Layout, scrollbars would appear.
I would be grateful for tips on how to implement this.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
LancerX0, 2017-01-13
@LancerX0

In this case, in the scrollArea, you should change the layout type to vertical:
Open the form -> RMB on the scrollArea in the object tree -> Layout (last line) -> Layout vertically.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question