PDA

View Full Version : subclass QSlider to go to a value on one click



THRESHE
26th May 2008, 16:29
Hi everybody

I'm writing a video player right now and I need a slider like in media player classic. I've was frustrated when I found that Qt does not have a way to go to the certain value on click. So I've tried to do it by subclassing QSlider like this:


void QProgressSlider::mouseReleaseEvent(QMouseEvent* event)
{
event->ignore();
double k = ((double)event->x())/((double)width());
int a = k*(maximum());
setValue(a);
}

This is close but some times the handle misses the cursor. I've also tried to use
int QSliderPrivate:: pixelPosToRangeValue(int pos) function but the results are the same.

Any suggestions ?

jpn
26th May 2008, 16:50
One can do it easily with good old proxy style:


int MyStyle::styleHint(StyleHint hint, const QStyleOption* option, const QWidget* widget, QStyleHintReturn* returnData) const
{
if (hint == SH_Slider_AbsoluteSetButtons)
return Qt::LeftButton; // or "Qt::LeftButton | Qt::RightButton"
return ProxyStyle::styleHint(hint, option, widget, returnData);
}

THRESHE
26th May 2008, 17:19
Any details ? :o

jpn
26th May 2008, 17:22
READ through the link I gave.