13 #include <QToolButton>
22 , FrameWidth_ { edit->style ()->pixelMetric (QStyle::PM_DefaultFrameWidth) }
23 , Pad_ { 1 + FrameWidth_ }
25 edit->installEventFilter (
this);
27 const auto markName =
"LC.Core.HasLineEditButtonManager";
28 if (edit->property (markName).toBool ())
30 std::string str {
"LineEditButtonManager is already installed on the edit" };
32 const auto& name = edit->objectName ();
34 str +=
" " + name.toStdString ();
36 throw std::runtime_error (str);
39 edit->setProperty (markName,
true);
42 void LineEditButtonManager::Add (QToolButton *button)
46 const auto& buttonSH = button->sizeHint ();
47 Pad_ += buttonSH.width ();
49 Edit_->setStyleSheet (QStringLiteral (
"QLineEdit { padding-right: %1px; }")
55 bool LineEditButtonManager::eventFilter (QObject *obj, QEvent *event)
61 return QObject::eventFilter (obj, event);
64 void LineEditButtonManager::UpdatePos ()
68 for (
const auto button : Buttons_)
70 const auto& hint = button->sizeHint ();
72 sumWidth += hint.width ();
74 const auto& rect = Edit_->rect ();
75 const int frameWidth = Edit_->style ()->pixelMetric (QStyle::PM_DefaultFrameWidth);
76 button->move (rect.right () - frameWidth - sumWidth,
77 (rect.bottom () + 1 - hint.height ()) / 2);