Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QSlider Value Changed Signal

Tags:

c++

qt4

qslider

I'm using a QSlider (v4.6) for input as well as to provide feedback to the user. For the feedback I will be calling the setValue method. I'm trying to find a signal that will fire only if the user modified the value. The valueChanged signal fires when the user changed the value as well as when I call setValue. sliderMoved only fires when the user drags the slider (not when using the keyboard). I checked the API docs and can't seem to find anything. Am I missing something? This seems something that would be common. If there is no other signal, how would you recommend that I simulate this functionality? Should I set a flag before calling setValue, disconnect and reconnect the signal every time I call setValue...?

like image 280
David Alvares Avatar asked Nov 10 '10 15:11

David Alvares


People also ask

What is QSlider?

QSlider provides methods for controlling tickmarks. You can use setTickPosition() to indicate where you want the tickmarks to be, setTickInterval() to indicate how many of them you want. the currently set tick position and interval can be queried using the tickPosition() and tickInterval() functions, respectively.

How do you make a slider in Qt?

Window::Window(QWidget *parent) : QWidget(parent) { horizontalSliders = new SlidersGroup(Qt::Horizontal, tr("Horizontal")); verticalSliders = new SlidersGroup(Qt::Vertical, tr("Vertical")); stackedWidget = new QStackedWidget; stackedWidget->addWidget(horizontalSliders); stackedWidget->addWidget(verticalSliders); ...


1 Answers

Good question, I checked the API and also couldn't find a signal that would be triggered only if value was modified by user. The workaround you proposed may be the only option, just keep in mind that you don't have to disconnect / connect all signals, just use QObject::blockSignals method:

slider->blockSignals(true); slider->setValue(x); slider->blockSignals(false); 

Hope that helps.

like image 117
Pawel Stolowski Avatar answered Oct 03 '22 20:10

Pawel Stolowski