Reputation: 11
I have about 5 push buttons and one slider. Every time I click the push button, the function for the particular push button gets called.
However, I also want the slider to do the same. So, instead of pressing the push button, you can drag the slider to the 5 different positions and it will do the same. However, I dont really know how I can connect 5 different positions of the sliders to each push button. Any help would be appreciated.
Thanks
Upvotes: 1
Views: 1896
Reputation: 4286
I don't even know what to say... it's kinda easy:
slider->setRange(0, 4);
connect(slider, SIGNAL(valueChanged(int)), SLOT(onSliderValueChanged(int)));
...
void Widget::onSliderValueChanged(int value)
{
switch (value)
{
case 0:
return onPushButton0Clicked();
...
}
}
void Widget::onPushButton0Clicked()
{
// do stuff
slider->blockSignals(true);
slider->setValue(0);
slider->blockSignals(false);
}
...
Upvotes: 2