7 #include <QStyleOption> 41 , m_buttonWidget(new QWidget(widget))
42 , m_buttonLayout(new QHBoxLayout(m_buttonWidget))
43 , m_clearButton(nullptr)
44 , m_infoButton(nullptr)
47 const QMargins margins = widget->contentsMargins();
49 opt.initFrom(m_widget);
50 const int frameWidth = widget->style()->pixelMetric(QStyle::PM_DefaultFrameWidth, &opt, m_widget);
52 m_buttonLayout->setContentsMargins(
53 margins.left() + frameWidth + pad, margins.top() + frameWidth, margins.right() + frameWidth + pad, margins.bottom() + frameWidth);
54 m_buttonLayout->setAlignment(Qt::AlignCenter | Qt::AlignRight);
55 widget->setLayout(m_buttonLayout);
72 m_buttonLayout->removeWidget(m_clearButton);
74 m_clearButton =
nullptr;
80 QIcon(QStringLiteral(
":/qtutilities/icons/hicolor/48x48/actions/" 83 m_clearButton->setGeometry(0, 0, 16, 16);
84 m_clearButton->setToolTip(QObject::tr(
"Clear"));
86 m_buttonLayout->addWidget(m_clearButton);
102 m_infoButton->setGeometry(0, 0, 16, 16);
103 QObject::connect(m_infoButton, &IconButton::clicked, std::bind(&ButtonOverlay::showInfo,
this));
105 m_buttonLayout->insertWidget(m_buttonLayout->count() - 2, m_infoButton);
107 m_buttonLayout->addWidget(m_infoButton);
111 m_infoButton->setToolTip(infoText);
121 m_buttonLayout->removeWidget(m_infoButton);
123 m_infoButton =
nullptr;
134 m_buttonLayout->addWidget(button);
144 m_buttonLayout->insertWidget(index, button);
154 m_buttonLayout->removeWidget(button);
165 m_clearButton->setVisible(visible);
193 void ButtonOverlay::showInfo()
196 QToolTip::showText(QCursor::pos(), m_infoButton->toolTip(), m_infoButton);