aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Arve Sæther <jan-arve.saether@qt.io>2020-09-30 19:18:48 +0200
committerJan Arve Sæther <jan-arve.saether@qt.io>2020-10-06 12:24:42 +0200
commitd1b4b38046388d7823ec66e8875301dc70e0db0f (patch)
tree4e273b543e3069dcebd74161658744a9fe9bda61
parent44b706274917af7836f4b5bdcd6b7975113a394f (diff)
nativestyle: SpinBox on Windows
Change-Id: I334af68282a59099698e46020b0644318eae5cce Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
-rw-r--r--src/imports/controls/windows/SpinBox.qml50
-rw-r--r--src/imports/nativestyle/items/qquickstyleitemspinbox.cpp2
-rw-r--r--src/imports/nativestyle/qstyle/qquickcommonstyle.cpp16
-rw-r--r--src/imports/nativestyle/qstyle/windows/qquickwindowsxpstyle.cpp8
-rw-r--r--tests/manual/nativestyle/SpinBoxes.qml1
5 files changed, 39 insertions, 38 deletions
diff --git a/src/imports/controls/windows/SpinBox.qml b/src/imports/controls/windows/SpinBox.qml
index e891aaf4..72309c60 100644
--- a/src/imports/controls/windows/SpinBox.qml
+++ b/src/imports/controls/windows/SpinBox.qml
@@ -35,7 +35,6 @@
****************************************************************************/
import QtQuick
-import QtQuick.Controls.impl
import QtQuick.Templates as T
import QtQuick.NativeStyle as NativeStyle
@@ -44,19 +43,17 @@ T.SpinBox {
property bool __nativeBackground: background instanceof NativeStyle.StyleItem
property bool nativeIndicators: up.indicator.hasOwnProperty("_qt_default")
- && down.indicator.hasOwnProperty("_qt_default")
+ && down.indicator.hasOwnProperty("_qt_default")
font.pixelSize: __nativeBackground ? background.styleFont(control).pixelSize : undefined
- implicitWidth: implicitBackgroundWidth + leftInset + rightInset
- implicitHeight: Math.max(implicitBackgroundHeight, up.implicitIndicatorHeight + down.implicitIndicatorHeight)
+ implicitWidth: Math.max(contentItem.implicitWidth + leftInset + rightInset,
+ 90 /* minimum */ )
+ implicitHeight: Math.max(contentItem.implicitHeight, up.implicitIndicatorHeight + down.implicitIndicatorHeight)
+ topInset + bottomInset
spacing: 2
- // Push the background right to make room for the indicators
- rightInset: nativeIndicators ? up.implicitIndicatorWidth + spacing : 0
-
leftPadding: __nativeBackground ? background.contentPadding.left: 0
topPadding: __nativeBackground ? background.contentPadding.top: 0
rightPadding: (__nativeBackground ? background.contentPadding.right : 0) + rightInset
@@ -68,7 +65,7 @@ T.SpinBox {
top: Math.max(control.from, control.to)
}
- contentItem: TextInput {
+ contentItem: TextField {
text: control.displayText
font: control.font
color: control.palette.text
@@ -77,14 +74,19 @@ T.SpinBox {
horizontalAlignment: Qt.AlignLeft
verticalAlignment: Qt.AlignVCenter
- topPadding: 2
- bottomPadding: 2
+ topPadding: 0
+ bottomPadding: 0
leftPadding: 10
rightPadding: 10
readOnly: !control.editable
validator: control.validator
inputMethodHints: control.inputMethodHints
+
+ // Since the indicators are embedded inside the TextField we need to avoid that
+ // the TextField consumes mouse events for that area.
+ // We achieve that by setting a containmentMask
+ containmentMask: Item { height: contentItem.height; width: contentItem.width - upAndDown.width }
}
NativeStyle.SpinBox {
@@ -94,29 +96,29 @@ T.SpinBox {
visible: nativeIndicators
x: up.indicator.x
y: up.indicator.y
+ //implicitHeight: contentItem.implicitHeight-2
+ height: parent.height-2
useNinePatchImage: false
+ z:99
}
up.indicator: Item {
- x: parent.width - width
- y: (parent.height / 2) - height
- implicitWidth: upAndDown.width
- implicitHeight: upAndDown.height / 2
+ x: parent.width - width - 2
+ y: 1
+ height: upAndDown.height >> 1
+ implicitWidth: upAndDown.implicitWidth
+ implicitHeight: (upAndDown.implicitHeight >> 1)
property bool _qt_default
}
down.indicator: Item {
- x: parent.width - width
- y: up.indicator.y + upAndDown.height / 2
- implicitWidth: upAndDown.width
- implicitHeight: upAndDown.height / 2
+ x: parent.width - width - 2
+ y: up.indicator.y + (upAndDown.height >> 1)
+ height: upAndDown.height - up.indicator.height
+ implicitWidth: upAndDown.implicitWidth
+ implicitHeight: upAndDown.implicitHeight >> 1
property bool _qt_default
}
- background: NativeStyle.SpinBox {
- control: control
- subControl: NativeStyle.SpinBox.Frame
- contentWidth: contentItem.implicitWidth
- contentHeight: contentItem.implicitHeight
- }
+ background: Item {} // No background, the TextField will cover the whole control
}
diff --git a/src/imports/nativestyle/items/qquickstyleitemspinbox.cpp b/src/imports/nativestyle/items/qquickstyleitemspinbox.cpp
index bfce65bb..7bae2c8b 100644
--- a/src/imports/nativestyle/items/qquickstyleitemspinbox.cpp
+++ b/src/imports/nativestyle/items/qquickstyleitemspinbox.cpp
@@ -89,7 +89,7 @@ void QQuickStyleItemSpinBox::initStyleOption(QStyleOptionSpinBox &styleOption)
styleOption.frame = true;
break;
case Up:
- styleOption.subControls = QStyle::SC_SpinBoxUp;
+ styleOption.subControls = (QStyle::SC_SpinBoxUp | QStyle::SC_SpinBoxDown);
break;
case Down:
styleOption.subControls = QStyle::SC_SpinBoxDown;
diff --git a/src/imports/nativestyle/qstyle/qquickcommonstyle.cpp b/src/imports/nativestyle/qstyle/qquickcommonstyle.cpp
index 6e662e3d..45f23f05 100644
--- a/src/imports/nativestyle/qstyle/qquickcommonstyle.cpp
+++ b/src/imports/nativestyle/qstyle/qquickcommonstyle.cpp
@@ -4652,11 +4652,17 @@ QSize QCommonStyle::sizeFromContents(ContentsType ct, const QStyleOption *opt, c
case CT_SpinBox:
if (const QStyleOptionSpinBox *vopt = qstyleoption_cast<const QStyleOptionSpinBox *>(opt)) {
// Add button + frame widths
- const qreal dpi = QStyleHelper::dpi(opt);
- const bool hasButtons = (vopt->buttonSymbols != QStyleOptionSpinBox::NoButtons);
- const int buttonWidth = hasButtons ? qRound(QStyleHelper::dpiScaled(16, dpi)) : 0;
- const int fw = vopt->frame ? proxy()->pixelMetric(PM_SpinBoxFrameWidth, vopt) : 0;
- sz += QSize(buttonWidth + 2*fw, 2*fw);
+ if (vopt->subControls == SC_SpinBoxFrame) {
+ const qreal dpi = QStyleHelper::dpi(opt);
+ const bool hasButtons = (vopt->buttonSymbols != QStyleOptionSpinBox::NoButtons);
+ const int buttonWidth = hasButtons ? qRound(QStyleHelper::dpiScaled(16, dpi)) : 0;
+ const int fw = vopt->frame ? proxy()->pixelMetric(PM_SpinBoxFrameWidth, vopt) : 0;
+ sz += QSize(buttonWidth + 2*fw, 1 + 2*fw);
+ } else {
+ const QSize buttonSize = proxy()->subControlRect(CC_SpinBox, vopt, SC_SpinBoxUp).size();
+ const int upAndDownTogetherHeight = buttonSize.height() * 2;
+ sz += QSize(buttonSize.width(), upAndDownTogetherHeight);
+ }
}
break;
case CT_Slider:
diff --git a/src/imports/nativestyle/qstyle/windows/qquickwindowsxpstyle.cpp b/src/imports/nativestyle/qstyle/windows/qquickwindowsxpstyle.cpp
index d736f832..69180c62 100644
--- a/src/imports/nativestyle/qstyle/windows/qquickwindowsxpstyle.cpp
+++ b/src/imports/nativestyle/qstyle/windows/qquickwindowsxpstyle.cpp
@@ -3406,14 +3406,6 @@ QSize QWindowsXPStyle::sizeFromContents(ContentsType ct, const QStyleOption *opt
}
}
break;
- case CT_SpinBox:
- {
- //Spinbox adds frame twice
- sz = QWindowsStyle::sizeFromContents(ct, option, contentsSize);
- int border = proxy()->pixelMetric(PM_SpinBoxFrameWidth, option);
- sz -= QSize(2*border, 2*border);
- }
- break;
case CT_TabWidget:
sz += QSize(6, 6);
break;
diff --git a/tests/manual/nativestyle/SpinBoxes.qml b/tests/manual/nativestyle/SpinBoxes.qml
index 60e2213b..552f159b 100644
--- a/tests/manual/nativestyle/SpinBoxes.qml
+++ b/tests/manual/nativestyle/SpinBoxes.qml
@@ -48,6 +48,7 @@ ControlContainer {
SpinBox {
value: 500
to: 2000
+ editable: true
}
SpinBox {