diff --git a/5.15.10/qtbase/src/plugins/styles/mac/qmacstyle_mac.mm b/5.15.10/qtbase/src/plugins/styles/mac/qmacstyle_mac.mm index c0c8788..b687283 100644 --- a/5.15.10/qtbase/src/plugins/styles/mac/qmacstyle_mac.mm +++ b/5.15.10/qtbase/src/plugins/styles/mac/qmacstyle_mac.mm @@ -468,7 +468,11 @@ static bool setupSlider(NSSlider *slider, const QStyleOptionSlider *sl) if (sl->minimum >= sl->maximum) return false; - slider.frame = sl->rect.toCGRect(); + // 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. + [slider initWithFrame:sl->rect.toCGRect()]; + slider.minValue = sl->minimum; slider.maxValue = sl->maximum; slider.intValue = sl->sliderPosition; @@ -498,6 +502,14 @@ 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; } @@ -844,6 +856,8 @@ static QSize qt_aqua_get_known_size(QStyle::ContentsType ct, const QWidget *widg return ret; } + const bool isBigSurOrAbove = QOperatingSystemVersion::current() >= QOperatingSystemVersion::MacOSBigSur; + if (ct == QStyle::CT_CustomBase && widg) { #if QT_CONFIG(pushbutton) if (qobject_cast(widg)) @@ -1038,6 +1052,8 @@ static QSize qt_aqua_get_known_size(QStyle::ContentsType ct, const QWidget *widg w = qt_mac_aqua_get_metric(HSliderHeight); if (sld->tickPosition() != QSlider::NoTicks) w += qt_mac_aqua_get_metric(HSliderTickHeight); + else if (isBigSurOrAbove) + w += 3; } else { w = qt_mac_aqua_get_metric(VSliderWidth); if (sld->tickPosition() != QSlider::NoTicks) diff --git a/5.15.10/qtbase/src/widgets/widgets/qslider.cpp b/5.15.10/qtbase/src/widgets/widgets/qslider.cpp index 0126914..a2cd35e 100644 --- a/5.15.10/qtbase/src/widgets/widgets/qslider.cpp +++ b/5.15.10/qtbase/src/widgets/widgets/qslider.cpp @@ -153,6 +153,13 @@ void QSlider::initStyleOption(QStyleOptionSlider *option) const option->pageStep = d->pageStep; if (d->orientation == Qt::Horizontal) option->state |= QStyle::State_Horizontal; + + if (d->pressedControl) { + option->activeSubControls = d->pressedControl; + option->state |= QStyle::State_Sunken; + } else { + option->activeSubControls = d->hoverControl; + } } bool QSliderPrivate::updateHoverControl(const QPoint &pos) @@ -315,12 +322,6 @@ void QSlider::paintEvent(QPaintEvent *) opt.subControls = QStyle::SC_SliderGroove | QStyle::SC_SliderHandle; if (d->tickPosition != NoTicks) opt.subControls |= QStyle::SC_SliderTickmarks; - if (d->pressedControl) { - opt.activeSubControls = d->pressedControl; - opt.state |= QStyle::State_Sunken; - } else { - opt.activeSubControls = d->hoverControl; - } style()->drawComplexControl(QStyle::CC_Slider, &opt, &p, this); }