7 #include <QStyleOption> 36 m_buttonWidget(new QWidget(widget)),
37 m_buttonLayout(new QHBoxLayout(m_buttonWidget)),
38 m_clearButton(nullptr),
42 const QMargins margins = widget->contentsMargins();
44 opt.initFrom(m_widget);
45 const int frameWidth = widget->style()->pixelMetric(QStyle::PM_DefaultFrameWidth, &opt, m_widget);
47 m_buttonLayout->setContentsMargins(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);
65 m_buttonLayout->removeWidget(m_clearButton);
67 m_clearButton =
nullptr;
72 m_clearButton->
setPixmap(QIcon(QStringLiteral(
":/qtutilities/icons/hicolor/48x48/actions/edit-clear.png")).pixmap(16));
73 m_clearButton->setGeometry(0, 0, 16, 16);
74 m_clearButton->setToolTip(QObject::tr(
"Clear"));
76 m_buttonLayout->addWidget(m_clearButton);
91 m_infoButton->setGeometry(0, 0, 16, 16);
92 QObject::connect(m_infoButton, &IconButton::clicked, std::bind(&ButtonOverlay::showInfo,
this));
94 m_buttonLayout->insertWidget(m_buttonLayout->count() - 2, m_infoButton);
96 m_buttonLayout->addWidget(m_infoButton);
100 m_infoButton->setToolTip(infoText);
110 m_buttonLayout->removeWidget(m_infoButton);
112 m_infoButton =
nullptr;
123 m_buttonLayout->addWidget(button);
133 m_buttonLayout->insertWidget(index, button);
143 m_buttonLayout->removeWidget(button);
154 m_clearButton->setVisible(visible);
181 void ButtonOverlay::showInfo()
184 QToolTip::showText(QCursor::pos(), m_infoButton->toolTip(), m_infoButton);