Commit 74b05b5c authored by J-P Nurmi's avatar J-P Nurmi
Browse files

Android: text entry implicit size fits 20 characters


A native unlayouted EditText control fits 20 characters by default.
Let Qt Quick Controls Android Style use the same metrics instead of
adjusting to the textual contents. This gives empty TextField,
SpinBox and ComboBox sensible implicit sizes instead of shrinking
them down to something unusable.

Change-Id: I3cd3948aa3d64daada9d0b7d773cebb6627263f6
Reviewed-by: default avatarMitch Curtis <mitch.curtis@digia.com>
Showing with 22 additions and 7 deletions
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
** $QT_END_LICENSE$ ** $QT_END_LICENSE$
** **
****************************************************************************/ ****************************************************************************/
import QtQuick 2.2 import QtQuick 2.4
import QtQuick.Window 2.2 import QtQuick.Window 2.2
import QtQuick.Controls 1.2 import QtQuick.Controls 1.2
import QtQuick.Controls.Private 1.0 import QtQuick.Controls.Private 1.0
...@@ -70,7 +70,7 @@ Style { ...@@ -70,7 +70,7 @@ Style {
readonly property real minWidth: styleDef.View_minWidth || 0 readonly property real minWidth: styleDef.View_minWidth || 0
readonly property real minHeight: styleDef.View_minHeight || 0 readonly property real minHeight: styleDef.View_minHeight || 0
readonly property real labelWidth: label.implicitWidth + paddingStart + paddingEnd readonly property real labelWidth: Math.max(label.implicitWidth, metrics.width) + paddingStart + paddingEnd
readonly property real labelHeight: label.implicitHeight + bg.padding.top + bg.padding.bottom readonly property real labelHeight: label.implicitHeight + bg.padding.top + bg.padding.bottom
implicitWidth: Math.max(minWidth, Math.max(bg.implicitWidth, labelWidth)) implicitWidth: Math.max(minWidth, Math.max(bg.implicitWidth, labelWidth))
...@@ -85,6 +85,11 @@ Style { ...@@ -85,6 +85,11 @@ Style {
styleDef: panel.styleDef.View_background styleDef: panel.styleDef.View_background
} }
TextMetrics {
id: metrics
text: "12345678901234567890"
}
LabelStyle { LabelStyle {
id: label id: label
text: control.currentText text: control.currentText
......
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
** $QT_END_LICENSE$ ** $QT_END_LICENSE$
** **
****************************************************************************/ ****************************************************************************/
import QtQuick 2.2 import QtQuick 2.4
import QtQuick.Window 2.2 import QtQuick.Window 2.2
import QtQuick.Controls 1.2 import QtQuick.Controls 1.2
import QtQuick.Controls.Private 1.0 import QtQuick.Controls.Private 1.0
...@@ -58,7 +58,7 @@ Style { ...@@ -58,7 +58,7 @@ Style {
readonly property real contentWidth: Math.max(styleDef.View_minWidth || 0, styleData.contentWidth) readonly property real contentWidth: Math.max(styleDef.View_minWidth || 0, styleData.contentWidth)
readonly property real contentHeight: Math.max(styleDef.View_minHeight || 0, styleData.contentHeight) readonly property real contentHeight: Math.max(styleDef.View_minHeight || 0, styleData.contentHeight)
readonly property real labelWidth: label.implicitWidth + bg.padding.left + bg.padding.right readonly property real labelWidth: Math.max(label.implicitWidth, metrics.width) + bg.padding.left + bg.padding.right
readonly property real labelHeight: label.implicitHeight + bg.padding.top + bg.padding.bottom readonly property real labelHeight: label.implicitHeight + bg.padding.top + bg.padding.bottom
implicitWidth: Math.max(contentWidth, Math.max(bg.implicitWidth, labelWidth)) implicitWidth: Math.max(contentWidth, Math.max(bg.implicitWidth, labelWidth))
...@@ -88,6 +88,11 @@ Style { ...@@ -88,6 +88,11 @@ Style {
readonly property int horizontalAlignment: Qt.AlignLeft readonly property int horizontalAlignment: Qt.AlignLeft
readonly property int verticalAlignment: Qt.AlignVCenter readonly property int verticalAlignment: Qt.AlignVCenter
TextMetrics {
id: metrics
text: "12345678901234567890"
}
LabelStyle { LabelStyle {
id: label id: label
visible: false visible: false
......
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
** $QT_END_LICENSE$ ** $QT_END_LICENSE$
** **
****************************************************************************/ ****************************************************************************/
import QtQuick 2.2 import QtQuick 2.4
import QtQuick.Window 2.2 import QtQuick.Window 2.2
import QtQuick.Controls 1.2 import QtQuick.Controls 1.2
import QtQuick.Controls.Private 1.0 import QtQuick.Controls.Private 1.0
...@@ -56,7 +56,7 @@ Style { ...@@ -56,7 +56,7 @@ Style {
readonly property real minWidth: styleDef.View_minWidth || 0 readonly property real minWidth: styleDef.View_minWidth || 0
readonly property real minHeight: styleDef.View_minHeight || 0 readonly property real minHeight: styleDef.View_minHeight || 0
readonly property real labelWidth: label.implicitWidth + bg.padding.left + bg.padding.right readonly property real labelWidth: Math.max(label.implicitWidth, metrics.width) + bg.padding.left + bg.padding.right
readonly property real labelHeight: label.implicitHeight + bg.padding.top + bg.padding.bottom readonly property real labelHeight: label.implicitHeight + bg.padding.top + bg.padding.bottom
implicitWidth: Math.max(minWidth, Math.max(bg.implicitWidth, labelWidth)) implicitWidth: Math.max(minWidth, Math.max(bg.implicitWidth, labelWidth))
...@@ -81,10 +81,15 @@ Style { ...@@ -81,10 +81,15 @@ Style {
readonly property alias selectionColor: label.selectionColor readonly property alias selectionColor: label.selectionColor
readonly property color selectedTextColor: label.selectedTextColor readonly property color selectedTextColor: label.selectedTextColor
TextMetrics {
id: metrics
text: "12345678901234567890"
}
LabelStyle { LabelStyle {
id: label id: label
visible: false visible: false
text: control.text text: control.text || control.placeholderText
focused: control.activeFocus focused: control.activeFocus
window_focused: focused && control.Window.active window_focused: focused && control.Window.active
styleDef: panel.styleDef styleDef: panel.styleDef
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment