From 9ec97a8867d57919cb03a59df135ae6d90ccaf4b Mon Sep 17 00:00:00 2001 From: uggas Date: Wed, 18 Oct 2023 23:07:55 -0700 Subject: [PATCH] Add ability to set user defined toggle view action (#562) Co-authored-by: Harbinder Saggu --- src/DockWidget.cpp | 14 ++++++++++++++ src/DockWidget.h | 6 ++++++ 2 files changed, 20 insertions(+) diff --git a/src/DockWidget.cpp b/src/DockWidget.cpp index 86c96d9..d799faf 100644 --- a/src/DockWidget.cpp +++ b/src/DockWidget.cpp @@ -364,6 +364,20 @@ CDockWidget::~CDockWidget() delete d; } +//============================================================================ +void CDockWidget::setToggleViewAction(QAction* action) +{ + if (!action) + { + return; + } + + d->ToggleViewAction->setParent(nullptr); + delete d->ToggleViewAction; + d->ToggleViewAction = action; + d->ToggleViewAction->setParent(this); + connect(d->ToggleViewAction, &QAction::triggered, this, &CDockWidget::toggleView); +} //============================================================================ void CDockWidget::setToggleViewActionChecked(bool Checked) diff --git a/src/DockWidget.h b/src/DockWidget.h index b27130e..b563c63 100644 --- a/src/DockWidget.h +++ b/src/DockWidget.h @@ -409,6 +409,12 @@ public: */ QAction* toggleViewAction() const; + /** + * Use provided action to be the default toggle view action for this dock widget. + * This dock widget now owns the action. + */ + void setToggleViewAction(QAction* action); + /** * Configures the behavior of the toggle view action. * \see eToggleViewActionMode for a detailed description