diff options
author | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2020-09-16 14:56:39 +0200 |
---|---|---|
committer | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2020-09-17 14:14:52 +0200 |
commit | e5827955cfae9928d4d0213b7db51f72fd765562 (patch) | |
tree | f850ef613b0304a72ad9e84fad803689b74e353b /src/imports/nativestyle/controls | |
parent | ae6132cb20584357fb342ef51f15523e53b7532a (diff) |
Native style: implement implicit minimum size
QStyle doesn't calculate a sensible minimum implicit size for us, only
a implicit size that matches the size of the contents. This means that
if the contents is empty (e.g a TextField that has no text), the implicit
size will typically be smaller than what a sensible minimum should be.
Note that for widgets, a sensible preffered size is set from the widgets
themselves, and not QStyle. Which explains why the sizes we get from
QStyle can sometimes be too small.
Therefore, add a sensible minimum implicit size to all the controls
that suffers from this problem. We let QStyle continue to calculate
the actual minimum size given the contents as before (which will end
up as the StyleItem's implicit size), and instead fix the recommended
minimum size directly in the QML style files.
Change-Id: Ic4097776e40d0de64312e4099d7fe4c7fc1ca9d1
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src/imports/nativestyle/controls')
5 files changed, 17 insertions, 9 deletions
diff --git a/src/imports/nativestyle/controls/DefaultComboBox.qml b/src/imports/nativestyle/controls/DefaultComboBox.qml index 1205d0b6..91726921 100644 --- a/src/imports/nativestyle/controls/DefaultComboBox.qml +++ b/src/imports/nativestyle/controls/DefaultComboBox.qml @@ -47,7 +47,8 @@ T.ComboBox { readonly property bool nativeBackground: background instanceof NativeStyle.StyleItem implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset, - implicitContentWidth + leftPadding + rightPadding) + implicitContentWidth + leftPadding + rightPadding, + 90 /* minimum */ ) implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset, implicitContentHeight + topPadding + bottomPadding, implicitIndicatorHeight + topPadding + bottomPadding) diff --git a/src/imports/nativestyle/controls/DefaultDial.qml b/src/imports/nativestyle/controls/DefaultDial.qml index 0f1d2c7d..42cc1271 100644 --- a/src/imports/nativestyle/controls/DefaultDial.qml +++ b/src/imports/nativestyle/controls/DefaultDial.qml @@ -45,9 +45,11 @@ T.Dial { readonly property bool nativeBackground: background instanceof NativeStyle.StyleItem implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset, - implicitContentWidth + leftPadding + rightPadding) + implicitContentWidth + leftPadding + rightPadding, + 80 /* minimum */ ) implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset, - implicitContentHeight + topPadding + bottomPadding) + implicitContentHeight + topPadding + bottomPadding, + 80 /* minimum */ ) font.pixelSize: nativeBackground ? background.styleFont(control).pixelSize : undefined diff --git a/src/imports/nativestyle/controls/DefaultProgressBar.qml b/src/imports/nativestyle/controls/DefaultProgressBar.qml index 0bf23ec4..80b0b94a 100644 --- a/src/imports/nativestyle/controls/DefaultProgressBar.qml +++ b/src/imports/nativestyle/controls/DefaultProgressBar.qml @@ -45,9 +45,11 @@ T.ProgressBar { readonly property bool nativeBackground: background instanceof NativeStyle.StyleItem implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset, - implicitContentWidth + leftPadding + rightPadding) + implicitContentWidth + leftPadding + rightPadding, + control.horizontal ? 90 : 0 /* minimum */ ) implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset, - implicitContentHeight + topPadding + bottomPadding) + implicitContentHeight + topPadding + bottomPadding, + control.vertical ? 90 : 0 /* minimum */ ) font.pixelSize: nativeIndicator ? indicator.styleFont(control).pixelSize : undefined diff --git a/src/imports/nativestyle/controls/DefaultSlider.qml b/src/imports/nativestyle/controls/DefaultSlider.qml index 8648143d..02459497 100644 --- a/src/imports/nativestyle/controls/DefaultSlider.qml +++ b/src/imports/nativestyle/controls/DefaultSlider.qml @@ -45,9 +45,11 @@ T.Slider { readonly property bool nativeBackground: background instanceof NativeStyle.StyleItem implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset, - implicitHandleWidth + leftPadding + rightPadding) + implicitHandleWidth + leftPadding + rightPadding, + control.horizontal ? 90 : 0 /* minimum */ ) implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset, - implicitHandleHeight + topPadding + bottomPadding) + implicitHandleHeight + topPadding + bottomPadding, + control.vertical ? 90 : 0 /* minimum */ ) font.pixelSize: nativeBackground ? background.styleFont(control).pixelSize : undefined diff --git a/src/imports/nativestyle/controls/DefaultSpinBox.qml b/src/imports/nativestyle/controls/DefaultSpinBox.qml index c959516a..100ccf6a 100644 --- a/src/imports/nativestyle/controls/DefaultSpinBox.qml +++ b/src/imports/nativestyle/controls/DefaultSpinBox.qml @@ -44,8 +44,9 @@ T.SpinBox { readonly property bool nativeBackground: background instanceof NativeStyle.StyleItem - implicitWidth: implicitBackgroundWidth + spacing + up.implicitIndicatorWidth - + leftInset + rightInset + implicitWidth: Math.max(implicitBackgroundWidth + spacing + up.implicitIndicatorWidth + + leftInset + rightInset, + 90 /* minimum */ ) implicitHeight: Math.max(implicitBackgroundHeight, up.implicitIndicatorHeight + down.implicitIndicatorHeight + (spacing * 3)) + topInset + bottomInset |