[Qt-interest] Again strange problem with QScrollArea

Oleg Shalnev oleg.shalnev at gmail.com
Thu Nov 26 20:49:30 CET 2009


Hi all.

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 tried to find what is the maximum value for
ScrollArea->verticalScrollBar() and found that it is less than real. You can
see it by sliderMove(int).

Where I am wrong? Help please! And how to scroll down to new element at the
bottom of the QScrollArea.


int Step=0;

TestWidget::TestWidget():QWidget
<http://doc.trolltech.com/latest/QWidget.html>()
{
    QVBoxLayout <http://doc.trolltech.com/latest/QVBoxLayout.html>
*InterfaceLayout=new QVBoxLayout
<http://doc.trolltech.com/latest/QVBoxLayout.html>(this);

    ScrollArea=new QScrollArea
<http://doc.trolltech.com/latest/QScrollArea.html>(this);
    ScrollArea->setWidgetResizable(true);
    ScrollArea->verticalScrollBar()->setMaximum(100);
    InterfaceLayout->addWidget(ScrollArea);
    connect(ScrollArea->verticalScrollBar(), SIGNAL(sliderMoved(int)),
this, SLOT(sliderMove(int)));

    ScrollWidget=new QWidget
<http://doc.trolltech.com/latest/QWidget.html>(this);
    ScrollWidgetLayout=new QVBoxLayout
<http://doc.trolltech.com/latest/QVBoxLayout.html>(ScrollWidget);
    ScrollWidgetLayout->setSpacing(0);
    ScrollWidgetLayout->setMargin(0);
    ScrollArea->setWidget(ScrollWidget);


    NewButton=new QPushButton
<http://doc.trolltech.com/latest/QPushButton.html>("new", this);
    InterfaceLayout->addWidget(NewButton);
    connect(NewButton, SIGNAL(clicked()), this, SLOT(newWidget()));

    resize(200, 300);
}

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

    QPushButton <http://doc.trolltech.com/latest/QPushButton.html>
*nButton=new QPushButton
<http://doc.trolltech.com/latest/QPushButton.html>(QString
<http://doc.trolltech.com/latest/QString.html>::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();

}



-- 
Oleg Shalnev         (Kalpa Project)
----------------------------------------------
mailto: oleg at kalpa.ru
skype:  oleg_shalnev
jabber:  oleg.shalnev at gmail.com
icq:        366619571
http://kalpa.ru
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20091126/d3dc2073/attachment.html 


More information about the Qt-interest-old mailing list