Reputation: 4136
i have a slider and apart from the scale that i was able to make it to be shown i want a label that shows me what's the current value of the slider, and when i slide it, it will change to the current position. Something like in this link from qwt.sorceforge.net
http://qwt.sourceforge.net/sliders.png
here's my slider code:
Slider = new QwtSlider(centralWidget);
Slider->setObjectName(QString::fromUtf8("Slider"));
Slider->setGeometry(QRect(520, 40, 60, 500));
QSizePolicy sizePolicy1(QSizePolicy::Expanding, QSizePolicy::Fixed);
sizePolicy1.setHorizontalStretch(0);
sizePolicy1.setVerticalStretch(0);
sizePolicy1.setHeightForWidth(Slider->sizePolicy().hasHeightForWidth());
Slider->setSizePolicy(sizePolicy1);
QFont font;
font.setFamily(QString::fromUtf8("Bitstream Charter"));
font.setPointSize(9);
Slider->setFont(font);
Slider->setCursor(QCursor(Qt::ArrowCursor));
Slider->setOrientation(Qt::Vertical);
Slider->setScalePosition(QwtSlider::LeftScale);
Slider->setBgStyle(QwtSlider::BgTrough);
Slider->setThumbLength(20);
Slider->setThumbWidth(10);
Slider->setBorderWidth(2);
Slider->setRange(xmin, xmax, step);
Slider->setScale(xmin, xmax+1, (xmax+1)/16);
Upvotes: 0
Views: 2708
Reputation: 29966
Connect the slider's valueChanged(int)
signal with a slot of your own:
connect( slider, SIGNAL(valueChanged(int)),
someClassThatHasSlot, SLOT(setValueToTheLabel(int)) );
And in the slot just do something like
void setValueToTheLabel( int value )
{
ui.yourLabel->setText( QString::number( value ) );
}
Upvotes: 3