karim
karim

Reputation: 217

Scrolling a Scroll Area in Qt

I just have a Scroll Area widget that consists of several QLabels.

Take a look at the situation:

Widgets Inside Scroll Area

I tried to do the following, but it didn't work out, it doesn't scroll.

#include "form1.h"
#include "form.h"
#include "ui_form.h"
#include "ui_form1.h"
#include<QScrollArea>
#include<QScrollBar>


Form::Form(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Form)
{
    ui->setupUi(this);
    ui->scrollAreaWidgetContents->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
    ui->scrollAreaWidgetContents->resize(ui->scrollArea->size().width() ,ui->scrollArea->size().height());
    ui->scrollArea->setWidgetResizable(true);
    ui->scrollArea->setWidget(ui->scrollAreaWidgetContents);
    ui->scrollAreaWidgetContents->adjustSize();

}

Upvotes: 2

Views: 15958

Answers (1)

Dirk
Dirk

Reputation: 1234

Did you apply a layout to the QScrollArea?

In the designer, select the QScrollArea and then click on one of the layout buttons (or press CTRL-L). This may not give you exactly what you want, but if things can then scroll, you know that the layout is the problem.

Upvotes: 7

Related Questions