diff options
author | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2020-06-04 10:04:34 +0200 |
---|---|---|
committer | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2020-06-04 15:53:14 +0000 |
commit | e23c0978043ed2e03c94be9fb4afec17f530b589 (patch) | |
tree | 9b60239e165672b4ea6b656a96a5b2eaf0f51d6a | |
parent | 53bfe56fc72000276c4f066de64ad1296bad496b (diff) |
Native style: let DefaultTextField have correct contentRect and size
Set implicitWidth/Height to be the same as in TextField.qml in the
default style (and the same for TextArea). And fix the mac style to
return correct values when calculating the minimum size. Combined, this
should ensure that we improve how we take the content size into account
when calculting the implicit size of a TextField (especially on macOS).
Change-Id: I39bc8bb0f238dd29d5fe33fc32d888b82d020b0e
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
-rw-r--r-- | src/imports/nativestyle/controls/DefaultTextArea.qml | 8 | ||||
-rw-r--r-- | src/imports/nativestyle/controls/DefaultTextField.qml | 7 | ||||
-rw-r--r-- | src/imports/nativestyle/qstyle/mac/qquickmacstyle_mac.mm | 23 |
3 files changed, 34 insertions, 4 deletions
diff --git a/src/imports/nativestyle/controls/DefaultTextArea.qml b/src/imports/nativestyle/controls/DefaultTextArea.qml index bb948e58..29277414 100644 --- a/src/imports/nativestyle/controls/DefaultTextArea.qml +++ b/src/imports/nativestyle/controls/DefaultTextArea.qml @@ -45,8 +45,12 @@ T.TextArea { readonly property bool nativeBackground: background instanceof NativeStyle.StyleItem - implicitWidth: Math.max(96, background.implicitWidth + leftPadding + rightPadding + leftInset + rightInset) - implicitHeight: background.implicitHeight + topPadding + bottomPadding + topInset + bottomInset + implicitWidth: Math.max(contentWidth + leftPadding + rightPadding, + implicitBackgroundWidth + leftInset + rightInset, + placeholder.implicitWidth + leftPadding + rightPadding) + implicitHeight: Math.max(contentHeight + topPadding + bottomPadding, + implicitBackgroundHeight + topInset + bottomInset, + placeholder.implicitHeight + topPadding + bottomPadding) font.pixelSize: nativeBackground ? background.styleFont(control).pixelSize : undefined diff --git a/src/imports/nativestyle/controls/DefaultTextField.qml b/src/imports/nativestyle/controls/DefaultTextField.qml index 847847b5..8df069d8 100644 --- a/src/imports/nativestyle/controls/DefaultTextField.qml +++ b/src/imports/nativestyle/controls/DefaultTextField.qml @@ -45,8 +45,11 @@ T.TextField { readonly property bool nativeBackground: background instanceof NativeStyle.StyleItem - implicitWidth: Math.max(96, background.implicitWidth + leftPadding + rightPadding + leftInset + rightInset) - implicitHeight: background.implicitHeight + topPadding + bottomPadding + topInset + bottomInset + implicitWidth: implicitBackgroundWidth + leftInset + rightInset + || Math.max(contentWidth, placeholder.implicitWidth) + leftPadding + rightPadding + implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset, + contentHeight + topPadding + bottomPadding, + placeholder.implicitHeight + topPadding + bottomPadding) font.pixelSize: nativeBackground ? background.styleFont(control).pixelSize : undefined diff --git a/src/imports/nativestyle/qstyle/mac/qquickmacstyle_mac.mm b/src/imports/nativestyle/qstyle/mac/qquickmacstyle_mac.mm index 0741288f..44e49d0e 100644 --- a/src/imports/nativestyle/qstyle/mac/qquickmacstyle_mac.mm +++ b/src/imports/nativestyle/qstyle/mac/qquickmacstyle_mac.mm @@ -6053,6 +6053,29 @@ QSize QMacStyle::sizeFromContents(ContentsType ct, const QStyleOption *opt, cons } } break; + case CT_LineEdit: + if (const QStyleOptionFrame *f = qstyleoption_cast<const QStyleOptionFrame *>(opt)) { + if (sz.isEmpty()) { + // Minimum size (10, 10) + sz.rwidth() += 2; + sz.rheight() += 6; + } + // From using pixelTool with XCode/NSTextTextField + int leftPadding = 4; + int rightPadding = 4; + int topPadding = 4; + int bottomPadding = 0; + + if (opt->state & QStyle::State_Small) { + topPadding = 3; + } else if (opt->state & QStyle::State_Mini) { + topPadding = 2; + } + + sz.rwidth() += leftPadding + rightPadding; + sz.rheight() += topPadding + bottomPadding; + } + break; case QStyle::CT_PushButton: { if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) if (btn->features & QStyleOptionButton::CommandLinkButton) |