Another thead about QScrollArea
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.
Code:
int Step=0;
{
ScrollArea->setWidgetResizable(true);
ScrollArea->verticalScrollBar()->setMaximum(100);
InterfaceLayout->addWidget(ScrollArea);
connect(ScrollArea->verticalScrollBar(), SIGNAL(sliderMoved(int)), this, SLOT(sliderMove(int)));
ScrollWidgetLayout->setSpacing(0);
ScrollWidgetLayout->setMargin(0);
ScrollArea->setWidget(ScrollWidget);
InterfaceLayout->addWidget(NewButton);
connect(NewButton, SIGNAL(clicked()), this, SLOT(newWidget()));
resize(200, 300);
}
void TestWidget::newWidget()
{
Step++;
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
Re: Another thead about QScrollArea
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.
Re: Another thead about QScrollArea
I found only one way to scroll down the QScrollArea
Code:
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.