From 1012b66f4f344d747196a6dc8022f5049d6f1b2d Mon Sep 17 00:00:00 2001 From: Alfredo Monclus Date: Sat, 15 Mar 2025 14:37:42 -0300 Subject: [PATCH] Gui: fix spinbox numbers should not go under the icon --- src/Gui/QuantitySpinBox.cpp | 8 -------- src/Gui/SpinBox.cpp | 8 ++++++++ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Gui/QuantitySpinBox.cpp b/src/Gui/QuantitySpinBox.cpp index 38a265e38a..abfbb04e34 100644 --- a/src/Gui/QuantitySpinBox.cpp +++ b/src/Gui/QuantitySpinBox.cpp @@ -282,14 +282,6 @@ QuantitySpinBox::QuantitySpinBox(QWidget *parent) this, [&]{ this->handlePendingEmit(true); }); - - // When a style sheet is set the text margins for top/bottom must be set to avoid to squash the widget -#ifndef Q_OS_MAC - lineEdit()->setTextMargins(0, 2, 0, 2); -#else - // https://forum.freecad.org/viewtopic.php?f=8&t=50615 - lineEdit()->setTextMargins(0, 2, 0, 0); -#endif } QuantitySpinBox::~QuantitySpinBox() = default; diff --git a/src/Gui/SpinBox.cpp b/src/Gui/SpinBox.cpp index 052e27cbbc..fbdcfc1abe 100644 --- a/src/Gui/SpinBox.cpp +++ b/src/Gui/SpinBox.cpp @@ -54,6 +54,14 @@ ExpressionSpinBox::ExpressionSpinBox(QAbstractSpinBox* sb) QObject::connect(iconLabel, &ExpressionLabel::clicked, [this]() { this->openFormulaDialog(); }); + + // Set Margins + // vertical to avoid this: https://forum.freecad.org/viewtopic.php?f=8&t=50615 + // horizontal to avoid going under the icon + lineedit->setAlignment(Qt::AlignVCenter); + int iconWidth = iconLabel->sizeHint().width(); + int margin = lineedit->style()->pixelMetric(QStyle::PM_LineEditIconMargin, nullptr, lineedit); + lineedit->setTextMargins(margin, margin, margin + iconWidth, margin); } ExpressionSpinBox::~ExpressionSpinBox() = default;