PDA

View Full Version : Another thead about QScrollArea



kalpa
26th November 2009, 15:26
Hi.

Here is standard test code for QScrollArea and standard task is to scroll down.

And QScrollArea don't scroll down. Just to the last but one element.

I try to find what is the maximum value for ScrollArea->verticalScrollBar() and found that it is less than real.

Where I am wrong? Help please! And how to scroll down to new element.



int Step=0;

TestWidget::TestWidget():QWidget()
{
QVBoxLayout *InterfaceLayout=new QVBoxLayout(this);

ScrollArea=new QScrollArea(this);
ScrollArea->setWidgetResizable(true);
ScrollArea->verticalScrollBar()->setMaximum(100);
InterfaceLayout->addWidget(ScrollArea);
connect(ScrollArea->verticalScrollBar(), SIGNAL(sliderMoved(int)), this, SLOT(sliderMove(int)));

ScrollWidget=new QWidget(this);
ScrollWidgetLayout=new QVBoxLayout(ScrollWidget);
ScrollWidgetLayout->setSpacing(0);
ScrollWidgetLayout->setMargin(0);
ScrollArea->setWidget(ScrollWidget);


NewButton=new QPushButton("new", this);
InterfaceLayout->addWidget(NewButton);
connect(NewButton, SIGNAL(clicked()), this, SLOT(newWidget()));

resize(200, 300);
}

void TestWidget::newWidget()
{
Step++;

QPushButton *nButton=new QPushButton(QString::number(Step), this);
nButton->setMinimumHeight(50);
ScrollWidgetLayout->addWidget(nButton);
nButton->show();

// ScrollArea->verticalScrollBar()->setValue(ScrollArea->verticalScrollBar()->maximum()+70);

qDebug()<<"maximum scroll"<<ScrollArea->verticalScrollBar()->maximum();

ScrollArea->ensureWidgetVisible(nButton);
}

void TestWidget::sliderMove(int)
{
qDebug()<<"Real value is"<<ScrollArea->verticalScrollBar()->value();

}


And QScrollArea don't scroll down. Just to the last but one element.
I try to find what is the maximum value for ScrollArea->verticalScrollBar() and found that it is less than real.

Where I am wrong? Help please! And how to scroll down to new element.

Thanks a lot

nish
27th November 2009, 11:09
i dont understand your code much but one thing i can say that.. if you use QScrollArea then never touch the scrollBars max and min value.. that is. dont set max and min of scrollbar... the scrollarea will take care of it.

kalpa
28th November 2009, 08:33
I found only one way to scroll down the QScrollArea


ScrollArea->verticalScrollBar()->setRange(0, widgetSize.height());
ScrollArea->verticalScrollBar()->setValue(ScrollArea->verticalScrollBar()->maximum());

And this solution using scrollbar.
If you know native way to scroll down, just show me.


And there in nothing understandably in my code.:)

Thanks a lot.