[Qt-interest] QSlider paint event: drawing the handle

Eric Kort eric.kort at exsilico.com
Sat Jun 11 15:48:41 CEST 2011


Thanks, Mark.

I looked at the source for qxtspanslider, and their approach was similar to mine.  However, I still cannot get it to work quite right and the reason is that QStylePainter::drawComplexControl seems to be ignoring QStyleOptionSlider::subControls.  As a result, all of the following result in both the groove and the handle being drawn (where opt is a QStyleOptionSlider instance):

opt.subControls = QStyle::SC_None;
opt.subControls = QStyle::SC_All;  \\ this gives the tick marks also
opt.subControls = QStyle::SC_SliderHandle;

As a result, when I draw the second slider handle, the slider groove gets redrawn over my first handle.  A screen shot is attached.  Here is the full paintEvent I am working with:

 void DoubleSlider::paintEvent(QPaintEvent *)
{
    QStylePainter painter(this);
    QStyleOptionSlider opt;
    opt.init(this);
    opt.orientation = Qt::Horizontal;
    opt.minimum = 0;
    opt.maximum = 100;
    opt.sliderPosition = 20; \\ just some arbitrary static values for demonstration
    opt.sliderValue = 20;
    opt.subControls = QStyle::SC_SliderHandle;
    painter.drawComplexControl(QStyle::CC_Slider, opt);
    opt.sliderPosition = 40;
    opt.sliderValue = 40;
    painter.drawComplexControl(QStyle::CC_Slider, opt);  // oops...groove gets redrawn!
    painter.end();
}

(Note that I am working with Qt 4.7.4 on Mac OS 10.6.7, 64 bit intel.  I am using the binary SDK distribution from qt.nokia.com.)

Thanks for any further insights you can offer!

-Eric

-------------- next part --------------
A non-text attachment was scrubbed...
Name: ss1.png
Type: image/png
Size: 21402 bytes
Desc: not available
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110611/f1d85d9b/attachment.png 
-------------- next part --------------


On Jun 10, 2011, at 7:14 PM, Mark Liversedge wrote:

> Check out qxtspanslider in the Qxt widgets, it does a range view.
> 
> Regards,
> Mark
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at qt.nokia.com
> http://lists.qt.nokia.com/mailman/listinfo/qt-interest
> 



More information about the Qt-interest-old mailing list