diff options
author | Yulong Bai <yulong.bai@qt.io> | 2018-02-13 16:33:32 +0100 |
---|---|---|
committer | Liang Qi <liang.qi@qt.io> | 2018-02-19 09:42:58 +0000 |
commit | 2be6033c4f19b97ca2073cd44b500397adb9270a (patch) | |
tree | 9929a426b36380c4aa283c05a4c02d26fc7078bb | |
parent | 58541d1c68fcf121318fe153e1469b9d0ebfec63 (diff) |
QFusionStyle: fix the checkbox rendering in low DPI settings
Fixed some regression of checkbox's size brought in by c9f68a5.
Using qreal and QRectF to avoid the round error accumulation
of sizes in low dpi situations.
Tweaked the look of the check mark.
Task-number: QTBUG-66343
Change-Id: Iad84f2f4503b53faf078ad52e13b6fbe88267426
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
(cherry picked from commit ea21b36836abd6c2bb6d139c9d4b8149acdc4785)
Reviewed-by: Liang Qi <liang.qi@qt.io>
-rw-r--r-- | src/widgets/styles/qfusionstyle.cpp | 35 |
1 files changed, 20 insertions, 15 deletions
diff --git a/src/widgets/styles/qfusionstyle.cpp b/src/widgets/styles/qfusionstyle.cpp index e6ad0fc898..82228af4c6 100644 --- a/src/widgets/styles/qfusionstyle.cpp +++ b/src/widgets/styles/qfusionstyle.cpp @@ -786,7 +786,7 @@ void QFusionStyle::drawPrimitive(PrimitiveElement elem, painter->drawRect(rect); QColor checkMarkColor = option->palette.text().color().darker(120); - const int checkMarkPadding = 1 + rect.width() * 0.2; // at least one pixel padding + const qreal checkMarkPadding = 1 + rect.width() * 0.13; // at least one pixel padding if (checkbox->state & State_NoChange) { gradient = QLinearGradient(rect.topLeft(), rect.bottomLeft()); @@ -798,20 +798,23 @@ void QFusionStyle::drawPrimitive(PrimitiveElement elem, painter->setPen(QPen(checkMarkColor, 1)); painter->setBrush(gradient); painter->drawRect(rect.adjusted(checkMarkPadding, checkMarkPadding, -checkMarkPadding, -checkMarkPadding)); + } else if (checkbox->state & State_On) { - qreal penWidth = QStyleHelper::dpiScaled(1.8); - penWidth = qMax(penWidth , 0.18 * rect.height()); - penWidth = qMin(penWidth , 0.30 * rect.height()); + qreal penWidth = QStyleHelper::dpiScaled(1.5); + penWidth = qMax(penWidth , 0.13 * rect.height()); + penWidth = qMin(penWidth , 0.20 * rect.height()); + QPen checkPen = QPen(checkMarkColor, penWidth); checkMarkColor.setAlpha(210); - painter->setPen(QPen(checkMarkColor, penWidth)); + painter->translate(dpiScaled(-0.8), dpiScaled(0.5)); + painter->setPen(checkPen); painter->setBrush(Qt::NoBrush); - painter->translate(-0.8, 0.5); // Draw checkmark QPainterPath path; - path.moveTo(1.33 * checkMarkPadding, rect.height() / 2.0); - path.lineTo(rect.width() / 2.0, rect.height() - checkMarkPadding); - path.lineTo(rect.width() - checkMarkPadding * 0.92, checkMarkPadding); + const qreal rectHeight = rect.height(); // assuming height equals width + path.moveTo(checkMarkPadding + rectHeight * 0.11, rectHeight * 0.47); + path.lineTo(rectHeight * 0.5, rectHeight - checkMarkPadding); + path.lineTo(rectHeight - checkMarkPadding, checkMarkPadding); painter->drawPath(path.translated(rect.topLeft())); } } @@ -1581,8 +1584,8 @@ void QFusionStyle::drawControl(ControlElement element, const QStyleOption *optio bool ignoreCheckMark = false; const int checkColHOffset = windowsItemHMargin + windowsItemFrame - 1; - int checkcol = qMax(menuItem->rect.height() * 0.7, - qMax(menuItem->maxIconWidth * 1.0, dpiScaled(17))); // icon checkbox's highlihgt column width + int checkcol = qMax(menuItem->rect.height() * 0.79, + qMax(menuItem->maxIconWidth * 1.0, dpiScaled(21))); // icon checkbox's highlihgt column width if ( #if QT_CONFIG(combobox) qobject_cast<const QComboBox*>(widget) || @@ -1591,10 +1594,12 @@ void QFusionStyle::drawControl(ControlElement element, const QStyleOption *optio ignoreCheckMark = true; //ignore the checkmarks provided by the QComboMenuDelegate if (!ignoreCheckMark) { - // Check - const int boxMargin = dpiScaled(4); - const int boxWidth = checkcol - 2 * boxMargin; - QRect checkRect(option->rect.left() + boxMargin + checkColHOffset, option->rect.center().y() - boxWidth/2 + 1, boxWidth, boxWidth); + // Check, using qreal and QRectF to avoid error accumulation + const qreal boxMargin = dpiScaled(3.5); + const qreal boxWidth = checkcol - 2 * boxMargin; + QRectF checkRectF(option->rect.left() + boxMargin + checkColHOffset, option->rect.center().y() - boxWidth/2 + 1, boxWidth, boxWidth); + QRect checkRect = checkRectF.toRect(); + checkRect.setWidth(checkRect.height()); // avoid .toRect() round error results in non-perfect square checkRect = visualRect(menuItem->direction, menuItem->rect, checkRect); if (checkable) { if (menuItem->checkType & QStyleOptionMenuItem::Exclusive) { |