QStyle: allow styles to control the margin around icons in QLineEdit

The styles can't control the margin of the icon container, and its value
is hardcoded to a quarter of the iconSize, which is very unfriendly.
Add a PixelMetric enum value to allow styles to control the margin.

Change-Id: I21274b68d24150db7be78513fe9125f775aa2b00
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
Wang Peng 2021-08-04 14:06:12 +08:00 committed by Volker Hilsheimer
parent b781fa79c1
commit 6dc9c89919
4 changed files with 8 additions and 2 deletions

View File

@ -4807,6 +4807,9 @@ int QCommonStyle::pixelMetric(PixelMetric m, const QStyleOption *opt, const QWid
case PM_LineEditIconSize:
ret = proxy()->pixelMetric(PM_SmallIconSize, opt, widget);
break;
case PM_LineEditIconMargin:
ret = proxy()->pixelMetric(PM_LineEditIconSize, opt, widget) / 4;
break;
case PM_LargeIconSize:
ret = int(QStyleHelper::dpiScaled(32, opt));

View File

@ -1519,6 +1519,9 @@ void QStyle::drawItemPixmap(QPainter *painter, const QRect &rect, int alignment,
\value PM_LineEditIconSize The default size for icons in a line edit.
This enum value has been introduced in Qt 6.2.
\value PM_LineEditIconMargin The margin around icons in a line edit.
This enum value has been introduced in Qt 6.3.
\value PM_CustomBase Base value for custom pixel metrics. Custom
values must be greater than this value.

View File

@ -568,7 +568,7 @@ public:
PM_TitleBarButtonSize,
PM_LineEditIconSize,
PM_LineEditIconMargin,
// do not add any values below/greater than this
PM_CustomBase = 0xf0000000
};

View File

@ -509,7 +509,7 @@ QLineEditPrivate::SideWidgetParameters QLineEditPrivate::sideWidgetParameters()
Q_Q(const QLineEdit);
SideWidgetParameters result;
result.iconSize = q->style()->pixelMetric(QStyle::PM_LineEditIconSize, nullptr, q);
result.margin = result.iconSize / 4;
result.margin = q->style()->pixelMetric(QStyle::PM_LineEditIconMargin, nullptr, q);
result.widgetWidth = result.iconSize + 6;
result.widgetHeight = result.iconSize + 2;
return result;