change labels by horizontal scrollbar

82 views Asked by At

I have an horizontal scrollbar which change the value (number) of two labels when I scroll it.

Bul, I also want that when you scroll it, it changes the picture on a stacket widget.

one picture when the value goes to 0-40, other when it´s from 41-70 and the last from 71-100.

The only thing I have achive is change the image but one by one. Anyone can help me? I´ve give you the code of this:

wave++;
if(wave==1)
{
     ui->VolumeSWWave_5->setCurrentIndex(1);
}

if(wave>1)
{
 wave=0;
     ui->VolumeSWWave_5->setCurrentIndex(0);
}

{
    return;
    for (int i = 0; i < 10; ++i)
        qDebug("%1", i);
}

if(wave<1)
{
    wave=0;
    ui->VolumeSWWave_5->setCurrentIndex(2);
}

{
    return;
    for (int i = 0; i > 10; ++i)
        qDebug("%1", i);
}
1

There are 1 answers

1
ΦXocę 웃 Пepeúpa ツ On

The QAbstractSlider has a signal (the actionTriggered(int)) if you "catch" that signal then you can in an if else block decide what picture is getting displayed:

void MainWindow::on_horizontalScrollBar_sliderMoved(int position)
{
    qDebug() << "position: " << position;
    if (position <= 40)
    {
        qDebug() << "set at index 1";
    }
    else if (position > 40 && position <= 71)
    {
        qDebug() << "set at index 2";
    }
    else
    {
        qDebug() << "set at index 3";
    }
}