[SOLVED] QSlider with timestamps
-
Hello friends!
I want to add timestamps above slider widget.
!http://s7.postimg.org/b6rj8xcq3/timeline2.png!
Center of each label exactly matches with the time on the slider.What is the simplest way to archive this?
-
you can give "QwtSlider":http://qwt.sourceforge.net a try if thats an option for you.
See "here":http://www.qtcentre.org/threads/51004-Customize-tick-labels-in-a-QwtSlider how to do so.If not and you want to stick to Qt libraries only. You will need to override the paintEvent() method of QSlider and replace the text of the ticks with your desired values. See Qt sources for reference.
-
Thank you, raven-worx!
I'll try QwtSlider right now. -
QwtSlider works perfectly. Maybe someone will need the code:
@
QwtDateScaleDraw *dsd = new QwtDateScaleDraw();
dsd->setDateFormat(QwtDate::Millisecond, "hh:mm");
dsd->setDateFormat(QwtDate::Second, "hh:mm");
dsd->setDateFormat(QwtDate::Minute, "hh:mm");
dsd->setDateFormat(QwtDate::Hour, "hh:mm");slider = new QwtSlider(Qt::Horizontal, this);
slider->setSpacing(0);
slider->setTotalSteps(600);
slider->setPageSteps(60);
slider->setScale(
1000.0QDateTime(QDate(2013, 9, 2), QTime(15, 0)).toTime_t(),
1000.0QDateTime(QDate(2013, 9, 2), QTime(15, 10)).toTime_t()
);
slider->setScaleStepSize(60000);
slider->setScaleMaxMajor(10);
slider->setScaleDraw(dsd);
slider->setHandleSize(QSize(20, 10));
@