Gui: add button group that allows to uncheck all buttons in exclusive mode

This commit is contained in:
wmayer
2021-11-22 23:00:30 +01:00
parent f5b880563e
commit b787f05d66
2 changed files with 50 additions and 0 deletions

View File

@@ -1664,4 +1664,34 @@ void ExpLineEdit::keyPressEvent(QKeyEvent *event)
QLineEdit::keyPressEvent(event);
}
// --------------------------------------------------------------------
ButtonGroup::ButtonGroup(QObject *parent)
: QButtonGroup(parent)
, _exclusive(true)
{
QButtonGroup::setExclusive(false);
connect(this, QOverload<QAbstractButton *>::of(&QButtonGroup::buttonClicked),
[=](QAbstractButton *button) {
if (exclusive()) {
for (auto btn : buttons()) {
if (btn && btn != button && btn->isCheckable())
btn->setChecked(false);
}
}
});
}
void ButtonGroup::setExclusive(bool on)
{
_exclusive = on;
}
bool ButtonGroup::exclusive() const
{
return _exclusive;
}
#include "moc_Widgets.cpp"