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;
{
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();
}
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();
}
To copy to clipboard, switch view to plain text mode
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
Bookmarks