7 #include <QStyleOption>
35 , m_buttonWidget(new QWidget(widget))
36 , m_buttonLayout(new QHBoxLayout(m_buttonWidget))
37 , m_clearButton(nullptr)
38 , m_infoButton(nullptr)
41 const QMargins margins = widget->contentsMargins();
43 opt.initFrom(m_widget);
44 const int frameWidth = widget->style()->pixelMetric(QStyle::PM_DefaultFrameWidth, &opt, m_widget);
46 m_buttonLayout->setContentsMargins(
47 margins.left() + frameWidth + pad, margins.top() + frameWidth, margins.right() + frameWidth + pad, margins.bottom() + frameWidth);
48 m_buttonLayout->setAlignment(Qt::AlignCenter | Qt::AlignRight);
49 widget->setLayout(m_buttonLayout);
66 m_buttonLayout->removeWidget(m_clearButton);
68 m_clearButton =
nullptr;
73 m_clearButton->
setPixmap(QIcon::fromTheme(QStringLiteral(
"edit-clear")).pixmap(16));
74 m_clearButton->setGeometry(0, 0, 16, 16);
75 m_clearButton->setToolTip(QObject::tr(
"Clear"));
77 m_buttonLayout->addWidget(m_clearButton);
93 m_infoButton->setGeometry(0, 0, 16, 16);
94 QObject::connect(m_infoButton, &IconButton::clicked, std::bind(&ButtonOverlay::showInfo,
this));
96 m_buttonLayout->insertWidget(m_buttonLayout->count() - 2, m_infoButton);
98 m_buttonLayout->addWidget(m_infoButton);
102 m_infoButton->setToolTip(infoText);
112 m_buttonLayout->removeWidget(m_infoButton);
114 m_infoButton =
nullptr;
125 m_buttonLayout->addWidget(button);
135 m_buttonLayout->insertWidget(index, button);
145 m_buttonLayout->removeWidget(button);
156 m_clearButton->setVisible(visible);
184 void ButtonOverlay::showInfo()
187 QToolTip::showText(QCursor::pos(), m_infoButton->toolTip(), m_infoButton);