Skip to content

Commit 0a8da95

Browse files
committed
QLineEdit: use height margins only when there is enough space
1 parent 18a2a25 commit 0a8da95

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

style/adwaita.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ namespace Adwaita
136136

137137
// line editors
138138
LineEdit_FrameWidth = 3,
139-
LineEdit_MarginHeight = 4,
139+
LineEdit_MarginHeight = 2,
140140
LineEdit_MarginWidth = 8,
141141
LineEdit_MinHeight = 36,
142142
LineEdit_MinWidth = 80,

style/adwaitastyle.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,9 +394,10 @@ void Style::polish(QWidget *widget)
394394
} else if (QLineEdit *lineEdit = qobject_cast<QLineEdit *>(widget)) {
395395
// Do not use additional margin if the QLineEdit is really small
396396
const bool useMarginWidth = lineEdit->width() > lineEdit->fontMetrics().width("#####");
397+
const bool useMarginHeight = lineEdit->height() > lineEdit->fontMetrics().height() + (2 * Metrics::LineEdit_MarginHeight);
398+
const int marginHeight = useMarginHeight ? Metrics::LineEdit_MarginHeight : 0;
397399
const int marginWidth = useMarginWidth ? Metrics::LineEdit_MarginWidth : 0;
398-
lineEdit->setTextMargins(marginWidth, Metrics::LineEdit_MarginHeight, marginWidth, Metrics::LineEdit_MarginHeight);
399-
lineEdit->setTextMargins(Metrics::LineEdit_MarginWidth, Metrics::LineEdit_MarginHeight, Metrics::LineEdit_MarginWidth, Metrics::LineEdit_MarginHeight);
400+
lineEdit->setTextMargins(marginWidth, marginHeight, marginWidth, marginHeight);
400401
} else if (QSpinBox *spinBox = qobject_cast<QSpinBox *>(widget)) {
401402
if (!spinBox->isEnabled()) {
402403
QPalette pal = spinBox->palette();

0 commit comments

Comments
 (0)