QAbstractSlider: fix missing "emission" of SliderOrientationChange

QAbstractSlider::sliderChange() is not a signal, but a protected
function, carrying an enum (also protected) to inform subclasses about
changes in the base class.

A user reported (QTBUG-135597) that in 5.15 the function was not
called for SliderOrientationChange. A prior test addition confirmed
that this bug is in all active branches.

Add the missing call in setOrientation().

This _should_ replace the update() call, because the default
sliderChange() implementation already calls it (and setPageStep(),
e.g., relies on this behavior), but since SliderOrientationChange was
not emitted since Qt 5.0, I minimize regression risks and keep the
update() call, just in case a user wrote code where they forgot to
call Base::sliderChange() for SliderOrientationChange (and this never
showed because we never "emitted" that, up to now). The duplicate
update() calls will be merged by Qt's event loop, so are harmless.

A dev-only follow-up change will remove the update().

[ChangeLog][QtWidgets][QAbstractSlider] Fixed the missing "emission"
of protected sliderChange(SliderOrientationChange).

Amends the start of the public history.

Pick-to: 6.5 5.15
Fixes: QTBUG-135597
Change-Id: I4545d47d315a98a9a51134901a00fa369f720754
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
(cherry picked from commit c35f6851bfe8ba71c26d3896498c1510fcd4e42b)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
(cherry picked from commit 4b20e23ed7a7c32b6557e526bf88804c48ac8325)
This commit is contained in:
Marc Mutz 2025-04-03 17:22:28 +02:00 committed by Qt Cherry-pick Bot
parent 61943ea3e7
commit 45e8c81c52
2 changed files with 1 additions and 4 deletions

View File

@ -272,6 +272,7 @@ void QAbstractSlider::setOrientation(Qt::Orientation orientation)
setSizePolicy(sizePolicy().transposed());
setAttribute(Qt::WA_WState_OwnSizePolicy, false);
}
sliderChange(SliderOrientationChange);
update();
updateGeometry();
}

View File

@ -2139,12 +2139,8 @@ void tst_QAbstractSlider::sliderChange_impl()
sl.setOrientation(sl.orientation() == Qt::Horizontal ? Qt::Vertical
/* else */ : Qt::Horizontal);
QEXPECT_FAIL("", "QTBUG-135597", Continue);
QCOMPARE(sl.changes.size(), 1U);
if (!sl.changes.empty()) {
QEXPECT_FAIL("", "QTBUG-135597", Continue);
QCOMPARE(sl.changes.back(), SliderChange::SliderOrientationChange);
}
sl.changes.clear();
sl.setPageStep(1025); // unlikely to be the default ;)