Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to connect a QSlider to QDoubleSpinBox

I want to connect a QSlider to a QDoubleSpinBox but while the code compiles fine and runs for simple QSpinBox, it doesn't work for QDoubleSpinBox

QSlider *horizontalSlider1 = new QSlider();
QDoubleSpinBox *spinBox1 = new QDoubleSpinBox();

connect(spinBox1, SIGNAL(valueChanged(double)),horizontalSlider1,SLOT(setValue(double)) );
connect(horizontalSlider1,SIGNAL(valueChanged(double)),spinBox1,SLOT(setValue(double)) );
like image 317
linello Avatar asked Jan 09 '12 16:01

linello


2 Answers

QSlider and QDoubleSpinBox take different types of arguments in valueChanged/setValue (QSlider uses ints and QDoubleSpinBox uses doubles, of course). Changing the argument type for the slider's signal and slot might help:

connect(spinBox1, SIGNAL(valueChanged(double)),horizontalSlider1,SLOT(setValue(int)) );
connect(horizontalSlider1,SIGNAL(valueChanged(int)),spinBox1,SLOT(setValue(double)) );

I'm not sure if Qt can automatically handle this type conversion for you; if not, you'll have to define your own slots to call setValue() on the correct object

like image 107
Dave Kilian Avatar answered Oct 04 '22 01:10

Dave Kilian


You'll have to add your own slot which converts the argument type and emits a signal or updates the slider directly.

like image 34
spraff Avatar answered Oct 03 '22 23:10

spraff