Skip to content

Commit fc87030

Browse files
committed
QLineEdit: do not use additional margins in case of small QLineEdit
1 parent 828d3ee commit fc87030

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

style/adwaitastyle.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,10 @@ void Style::polish(QWidget *widget)
392392
} else if (widget->inherits("QTipLabel")) {
393393
setTranslucentBackground(widget);
394394
} else if (QLineEdit *lineEdit = qobject_cast<QLineEdit *>(widget)) {
395+
// Do not use additional margin if the QLineEdit is really small
396+
const bool useMarginWidth = lineEdit->width() > lineEdit->fontMetrics().width("#####");
397+
const int marginWidth = useMarginWidth ? Metrics::LineEdit_MarginWidth : 0;
398+
lineEdit->setTextMargins(marginWidth, Metrics::LineEdit_MarginHeight, marginWidth, Metrics::LineEdit_MarginHeight);
395399
lineEdit->setTextMargins(Metrics::LineEdit_MarginWidth, Metrics::LineEdit_MarginHeight, Metrics::LineEdit_MarginWidth, Metrics::LineEdit_MarginHeight);
396400
} else if (QSpinBox *spinBox = qobject_cast<QSpinBox *>(widget)) {
397401
if (!spinBox->isEnabled()) {

0 commit comments

Comments
 (0)