diff --git a/src/plugins/styles/mac/qmacstyle_mac.mm b/src/plugins/styles/mac/qmacstyle_mac.mm index 15dcea13bd..2bab19d682 100644 --- a/src/plugins/styles/mac/qmacstyle_mac.mm +++ b/src/plugins/styles/mac/qmacstyle_mac.mm @@ -429,12 +429,7 @@ static bool setupSlider(NSSlider *slider, const QStyleOptionSlider *sl) if (sl->minimum >= sl->maximum) return false; - // NSSlider seems to cache values based on tracking and the last layout of the - // NSView, resulting in incorrect knob rects that break the interaction with - // multiple sliders. So completely reinitialize the slider. - const auto controlSize = slider.controlSize; - [slider initWithFrame:sl->rect.toCGRect()]; - slider.controlSize = controlSize; + slider.frame = sl->rect.toCGRect(); slider.minValue = sl->minimum; slider.maxValue = sl->maximum; @@ -465,14 +460,6 @@ static bool setupSlider(NSSlider *slider, const QStyleOptionSlider *sl) // the cell for its metrics and to draw itself. [slider layoutSubtreeIfNeeded]; - if (sl->state & QStyle::State_Sunken) { - const CGRect knobRect = [slider.cell knobRectFlipped:slider.isFlipped]; - CGPoint pressPoint; - pressPoint.x = CGRectGetMidX(knobRect); - pressPoint.y = CGRectGetMidY(knobRect); - [slider.cell startTrackingAt:pressPoint inView:slider]; - } - return true; } @@ -5386,6 +5373,15 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex const CGRect knobRect = [slider.cell knobRectFlipped:slider.isFlipped]; pressPoint.x = CGRectGetMidX(knobRect); pressPoint.y = CGRectGetMidY(knobRect); + + // The only way to tell a NSSlider/NSSliderCell to render as pressed + // is to start tracking. But this API has some weird behaviors that + // we have to account for. First of all, the pressed state will not + // be visually reflected unless we start tracking twice. And secondly + // if we don't track twice, the state of one render-pass will affect + // the render pass of other sliders, even if we set up the shared + // NSSlider with a new slider value. + [slider.cell startTrackingAt:pressPoint inView:slider]; [slider.cell startTrackingAt:pressPoint inView:slider]; } @@ -5490,8 +5486,12 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex } }); - if (isPressed) + if (isPressed) { + // We stop twice to be on the safe side, even if one seems to be enough. + // See startTracking above for why we do this. [slider.cell stopTracking:pressPoint at:pressPoint inView:slider mouseIsUp:NO]; + [slider.cell stopTracking:pressPoint at:pressPoint inView:slider mouseIsUp:NO]; + } } break; #if QT_CONFIG(spinbox)