34 #include <QToolButton> 45 , FrameWidth_ { edit->style ()->pixelMetric (QStyle::PM_DefaultFrameWidth) }
46 , Pad_ { 1 + FrameWidth_ }
48 edit->installEventFilter (
this);
50 if (edit->findChildren<LineEditButtonManager*> ().size () > 1)
52 std::string str {
"LineEditButtonManager is already installed on the edit" };
54 const auto& name = edit->objectName ();
56 str +=
" " + name.toStdString ();
58 throw std::runtime_error (str);
66 const auto& buttonSH = button->sizeHint ();
67 Pad_ += buttonSH.width ();
69 Edit_->setStyleSheet (QString (
"QLineEdit { padding-right: %1px; }")
81 return QObject::eventFilter (obj, event);
84 void LineEditButtonManager::UpdatePos ()
88 for (
const auto button : Buttons_)
90 const auto& hint = button->sizeHint ();
92 sumWidth += hint.width ();
94 const auto& rect = Edit_->rect ();
95 const int frameWidth = Edit_->style ()->pixelMetric (QStyle::PM_DefaultFrameWidth);
96 button->move (rect.right () - frameWidth - sumWidth,
97 (rect.bottom () + 1 - hint.height ()) / 2);