QStyleSheet: rotate QSizeGrip image around center

Depending on the corner that the size grip lives in, the style sheet
style rotates the painter before rendering the drawable. However, that
needs to be done around the center of the size grip, not around the
origin, as otherwise the image rotates out of the rect.

Use a static array to map the corner to the rotation value, and
translate/rotate/translate back only if there is a rotation.

Pick-to: 6.5
Fixes: QTBUG-112252
Change-Id: I59f69385bd6699ecc8db46390c5f7cc933574ce8
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
bb10
Volker Hilsheimer 2023-04-17 16:23:29 +02:00
parent cb30e45b9a
commit ca978e2c12
1 changed files with 5 additions and 6 deletions

View File

@ -4254,12 +4254,11 @@ void QStyleSheetStyle::drawControl(ControlElement ce, const QStyleOption *opt, Q
if (rule.hasDrawable()) {
rule.drawFrame(p, opt->rect);
p->save();
switch (sgOpt->corner) {
case Qt::BottomRightCorner: break;
case Qt::BottomLeftCorner: p->rotate(90); break;
case Qt::TopLeftCorner: p->rotate(180); break;
case Qt::TopRightCorner: p->rotate(270); break;
default: break;
static constexpr int rotation[] = { 180, 270, 90, 0 };
if (rotation[sgOpt->corner]) {
p->translate(opt->rect.center());
p->rotate(rotation[sgOpt->corner]);
p->translate(-opt->rect.center());
}
rule.drawImage(p, opt->rect);
p->restore();