From cec78cc680c4d7c78aee76e9bc05204713e17d12 Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich <gabriel.dedietrich@digia.com> Date: Thu, 28 Mar 2013 20:03:16 +0100 Subject: [PATCH] TextField: Fix baseline distance to panel frame Still not perfect, and both the cursor and selection height are one pixel too tall on Mac (and possibly Windows). On Ubuntu, Gtk 2 looks almost identical to native. Fusion also looks almost identical compared to QLineEdit. The basic idea is to override (again) what the style does, since we do the painting in the Qt Quick side. Change-Id: I179c2dfe6c76dd35f8bb87a5cd7c183f8e0f67e5 Reviewed-by: Jens Bache-Wiig <jens.bache-wiig@digia.com> --- src/private/qstyleitem.cpp | 15 ++++++++++++++- src/styles/Desktop/TextFieldStyle.qml | 5 +++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/private/qstyleitem.cpp b/src/private/qstyleitem.cpp index b02b3cf9a..b72ff4076 100644 --- a/src/private/qstyleitem.cpp +++ b/src/private/qstyleitem.cpp @@ -750,7 +750,20 @@ QSize QStyleItem::sizeFromContents(int width, int height) size = qApp->style()->sizeFromContents(QStyle::CT_ProgressBar, m_styleoption, QSize(width,height)); break; case Edit: - size = qApp->style()->sizeFromContents(QStyle::CT_LineEdit, m_styleoption, QSize(width,height)); +#ifdef Q_OS_MAC + if (style() =="mac") { + if (m_hints.indexOf("small") != -1 || m_hints.indexOf("mini") != -1) + size = QSize(width, 19); + else + size = QSize(width, 21); + } else +#endif + { + size = QSize(width, height); + if (const QStyleOptionFrame *f = qstyleoption_cast<const QStyleOptionFrame *>(m_styleoption)) + size += QSize(2*f->lineWidth, 2*f->lineWidth); + } + if (hints().indexOf("rounded") != -1) size += QSize(0, 3); break; diff --git a/src/styles/Desktop/TextFieldStyle.qml b/src/styles/Desktop/TextFieldStyle.qml index 5024ca861..59af59697 100644 --- a/src/styles/Desktop/TextFieldStyle.qml +++ b/src/styles/Desktop/TextFieldStyle.qml @@ -67,13 +67,14 @@ Style { property bool rounded: hints.indexOf("rounded") > -1 - property int topMargin: 1 + property int topMargin: style === "mac" ? 4 : 5 property int leftMargin: rounded ? 8 : 4 property int rightMargin: 4 property int bottomMargin: 1 contentWidth: 100 - contentHeight: 18 + // Form QLineEdit::sizeHint + contentHeight: Math.max(control.__contentHeight, 14) + topMargin + bottomMargin FocusFrame { anchors.fill: parent -- GitLab