5.5.14: fix for QTBUG-98093 (backport to 5.15)

This commit is contained in:
kleuter 2023-07-11 16:34:18 +02:00
parent 446a887d34
commit f5af6fb404
2 changed files with 24 additions and 7 deletions

View File

@ -468,7 +468,11 @@ static bool setupSlider(NSSlider *slider, const QStyleOptionSlider *sl)
if (sl->minimum >= sl->maximum) if (sl->minimum >= sl->maximum)
return false; 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.minValue = sl->minimum;
slider.maxValue = sl->maximum; slider.maxValue = sl->maximum;
slider.intValue = sl->sliderPosition; 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. // the cell for its metrics and to draw itself.
[slider layoutSubtreeIfNeeded]; [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; return true;
} }
@ -844,6 +856,8 @@ static QSize qt_aqua_get_known_size(QStyle::ContentsType ct, const QWidget *widg
return ret; return ret;
} }
const bool isBigSurOrAbove = QOperatingSystemVersion::current() >= QOperatingSystemVersion::MacOSBigSur;
if (ct == QStyle::CT_CustomBase && widg) { if (ct == QStyle::CT_CustomBase && widg) {
#if QT_CONFIG(pushbutton) #if QT_CONFIG(pushbutton)
if (qobject_cast<const QPushButton *>(widg)) if (qobject_cast<const QPushButton *>(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); w = qt_mac_aqua_get_metric(HSliderHeight);
if (sld->tickPosition() != QSlider::NoTicks) if (sld->tickPosition() != QSlider::NoTicks)
w += qt_mac_aqua_get_metric(HSliderTickHeight); w += qt_mac_aqua_get_metric(HSliderTickHeight);
else if (isBigSurOrAbove)
w += 3;
} else { } else {
w = qt_mac_aqua_get_metric(VSliderWidth); w = qt_mac_aqua_get_metric(VSliderWidth);
if (sld->tickPosition() != QSlider::NoTicks) if (sld->tickPosition() != QSlider::NoTicks)

View File

@ -153,6 +153,13 @@ void QSlider::initStyleOption(QStyleOptionSlider *option) const
option->pageStep = d->pageStep; option->pageStep = d->pageStep;
if (d->orientation == Qt::Horizontal) if (d->orientation == Qt::Horizontal)
option->state |= QStyle::State_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) bool QSliderPrivate::updateHoverControl(const QPoint &pos)
@ -315,12 +322,6 @@ void QSlider::paintEvent(QPaintEvent *)
opt.subControls = QStyle::SC_SliderGroove | QStyle::SC_SliderHandle; opt.subControls = QStyle::SC_SliderGroove | QStyle::SC_SliderHandle;
if (d->tickPosition != NoTicks) if (d->tickPosition != NoTicks)
opt.subControls |= QStyle::SC_SliderTickmarks; 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); style()->drawComplexControl(QStyle::CC_Slider, &opt, &p, this);
} }