PDA

View Full Version : QScrollArea no work properly in QWizardPage object



AleG
11th January 2011, 16:56
Hi everyone,
I'm finding some problems when I try to add a QScrollArea to QWizardPage widget.
Below is the code:

//header WizarPage file

#ifndef SCROLLPAGE_H
#define SCROLLPAGE_H

#include <QtGui>
#include <QWizardPage>

#define ITEM 20

class scrollPage: public QWizardPage
{
Q_OBJECT

public:
scrollPage(QWidget *parent = 0);

protected:
void initializePage();

private:
QLabel name[ITEM];
QLabel data[ITEM];
QPushButton ButInfo[ITEM];
QHBoxLayout lineH[ITEM];
};

#endif // SCROLLPAGE_H

//WizardPage implementation
scrollPage::scrollPage(QWidget *parent)
: QWizardPage(parent)
{
setTitle(tr("SCROLL page title"));

}

void scrollPage::initializePage()
{

int i = 0;
/* scroll area */
QScrollArea* sa = new QScrollArea;
sa->setWidgetResizable(true);

QScrollBar *scrollBar = sa->verticalScrollBar();
scrollBar->setSliderDown( true );

scrollBar->setValue(0);
sa->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
sa->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOf f);


QVBoxLayout * Elenco1 = new QVBoxLayout(sa);

sa->setLayout(Elenco1);

while(i< ITEM)
{
name[i].setText(tr("NAME"));
data[i].setText(tr("DATA"));
ButInfo[i].setText("Info");

lineH[i].addWidget(&name[i]);
lineH[i].addWidget(&data[i]);
lineH[i].addWidget(&ButInfo[i]);

Elenco1->addLayout(&lineH[i]);
i++;
}

QVBoxLayout * ShowLayout = new QVBoxLayout;
ShowLayout->addWidget(sa);

setLayout(ShowLayout);
}


When I run the program happens that the page displays a scroll area, but the layout is resized and the page does not scroll.

Unfortunately they are still a beginner, but if anyone can help I would be very grateful!

Sincerely,
Ale

AleG
12th January 2011, 09:23
I discovered the problem.
I had not considered the fact that QScrollArea use widgets and therefore perform a QScrollArea::SetWidget (widgwet). I modified the code as follows and now works correctly.

......
........
scrollBar->setValue(0);
sa->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
sa->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOf f);


QWidget* container = new QWidget(this);
QVBoxLayout * Elenco1 = new QVBoxLayout(container);
sa->setWidget(container);

......
...

while(i< ITEM)
{
......
.......
lineH[i].addWidget(&data[i]);
lineH[i].addWidget(&ButInfo[i]);
lineH[i].setSizeConstraint(lineH[i].SetFixedSize);

Elenco1->addLayout(&lineH[i]);
i++;
}
......
..