Valentin H
Valentin H

Reputation: 7448

How to ensure, the entire area in QScrollArea was displayed?

I'm displaying some information to the user in QScrollArea. The user should have seen all contents, before she can proceed (at least the content should have been scrolled to the end) How could I detect this in an easily?

Is the reimplementing of virtual void scrollContentsBy (int dx,int dy) the only way?

EDIT

I was able to solve it, but had to use some workarounds:

  1. Scroll-action value sent by the signal actionTriggered(int) had never the value QAbstractSlider::SliderToMaximum (Qt4.8, Windows 7). So I've checked manually, if the slider value is close to maximum.
  2. Even if scroll-bar widget was dragged by mouse till the bottom, the value of the scroll-bar is never the maximum. Only if the scroll-bar widget is moved by any other event such as arrow-down or mouse wheel, the value may become maximum. I've work-arounded it with recheckPosition()

I hope, there are better solutions.

void NegativeConfirmation::recheckPosition()
{
    processScrollAction(1);
}

void NegativeConfirmation::processScrollAction( int evt)
{

if ( evt == QAbstractSlider::SliderToMaximum) // Have not managed to receive this action
{
    ui->bConfirm->setEnabled(true);
}

//Another approach
QWidget * sw = ui->scrollArea->widget();
if ( sw ) //any content at all ?
{       
    QScrollBar * sb = ui->scrollArea->verticalScrollBar();
    if ( sb ) 
    {           
        int sbv = sb->value();
        int sbm = sb->maximum()-10;
        if ( sbm>0 && sbv >= sbm )
        {
            ui->bConfirm->setEnabled(true);             
        }
        else
        {
            QTimer::singleShot(1000, this, SLOT(recheckPosition()));
        }
    }
}

}

Upvotes: 1

Views: 372

Answers (1)

TheDarkKnight
TheDarkKnight

Reputation: 27611

QScrollArea inherits QAbstractSlider which provides this signal: -

void QAbstractSlider::actionTriggered(int action)

Where action can be QAbstractSlider::SliderToMaximum.

I expect you can connect to the this signal and test when the action is QAbstractSlider::SliderToMaximum, representing that the user has scrolled to the bottom.

Upvotes: 1

Related Questions