Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

qslider sliderReleased value

Tags:

c++

qt

qslider

I m trying to make a media player . The time status of the track is shown using QSlider. Track seek should happen when the user releases the slider somewhere on the QSlider. I had a look on the list of QSlider signals. The one that seems to fit is sliderReleased() which happens when the user releases the slider, but it does not get the latest value of where slider is. So to get sliders latest value I used sliderMoved() and stored reference.

Signal and slot connection

connect(this->ui->songProgress, SIGNAL(sliderMoved(int)), this,
SLOT(searchSliderMoved(int)));
connect(this->ui->songProgress, SIGNAL(sliderReleased()), this,
SLOT(searchSliderReleased()));

Functions

  void MainWindow::searchSliderMoved(int search_percent)
    {
        value=this->ui->songProgress->value();
        std::cout<<"Moved: Slider value"<<value<<std::endl;
    }

Now I am Using the "value" variable inside searchSliderReleased for seeking

void MainWindow::searchSliderReleased()
{
    std::cout<<"Released: Slider value"<<value<<std::endl;

    emit search(value);//seek the track to location value
}

But the problem with above technique is that sliderMoved signal does not give the value where the slider is dropped but it give the location from where the slider was moved. How do I obtain the value where the slider was dropped?

like image 288
Vihaan Verma Avatar asked Aug 16 '26 09:08

Vihaan Verma


1 Answers

Had the same problem and calling sliderPosition() instead of value() directly when handling sliderReleased() worked for me.

like image 112
user666412 Avatar answered Aug 19 '26 05:08

user666412



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!