Commit 9ed865ad authored by Caio Tonetti's avatar Caio Tonetti
Browse files

sidedockwidget: Fix on the exclusive button group of the toolbar

parent 385417af
...@@ -45,6 +45,8 @@ SideToolButton::SideToolButton(QWidget *parent) ...@@ -45,6 +45,8 @@ SideToolButton::SideToolButton(QWidget *parent)
setCheckable(true); setCheckable(true);
setAutoRaise(true); setAutoRaise(true);
setToolButtonStyle(Qt::ToolButtonTextBesideIcon); setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
wasChecked = false;
} }
Qt::Orientation SideToolButton::orientation() const Qt::Orientation SideToolButton::orientation() const
...@@ -82,7 +84,7 @@ QSize SideToolButton::sizeHint() const ...@@ -82,7 +84,7 @@ QSize SideToolButton::sizeHint() const
void SideToolButton::paintEvent(QPaintEvent *event) void SideToolButton::paintEvent(QPaintEvent *event)
{ {
Q_UNUSED(event); Q_UNUSED(event)
// rotated paint // rotated paint
QStylePainter painter(this); QStylePainter painter(this);
...@@ -144,12 +146,28 @@ void SidedockWidget::addDock(QWidget* widget, const QString& title, const QIcon& ...@@ -144,12 +146,28 @@ void SidedockWidget::addDock(QWidget* widget, const QString& title, const QIcon&
button->setIcon(icon); button->setIcon(icon);
button->setShortcut(QKeySequence()); button->setShortcut(QKeySequence());
button->setChecked(false); // initially do not check button->setChecked(false); // initially do not check
_btnGroup->addButton(button); _btnGroup->addButton(button);
// only request action on user set action // only request action on user set action
const int idx = _widgets.count(); const int idx = _widgets.count();
connect(button, &SideToolButton::clicked, this, connect(button, &SideToolButton::clicked, this,
[this, button, idx] { [this, button, idx] {
// Force uncheck the button because of the exclusive
// Without this the toolbar buttons cannot be all unchecked
// after one is clicked4
if (button->wasChecked) {
_btnGroup->setExclusive(false);
button->setChecked(false);
_btnGroup->setExclusive(true);
button->wasChecked = false;
} else {
button->wasChecked = true;
}
showDock(button->isChecked(), idx); showDock(button->isChecked(), idx);
}); });
......
...@@ -44,6 +44,8 @@ public: ...@@ -44,6 +44,8 @@ public:
Qt::Orientation orientation() const; Qt::Orientation orientation() const;
QSize sizeHint() const Q_DECL_OVERRIDE; QSize sizeHint() const Q_DECL_OVERRIDE;
bool wasChecked;
protected: protected:
void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE; void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
}; };
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment