Skip to content

Commit f5242c0

Browse files
committed
UI,docs: Send a custom event to the dock widget when closing
1 parent 7843a82 commit f5242c0

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

UI/window-basic-main.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,8 @@ OBSBasic::OBSBasic(QWidget *parent)
328328

329329
setContextMenuPolicy(Qt::CustomContextMenu);
330330

331+
QEvent::registerEventType(QEvent::User + QEvent::Close);
332+
331333
api = InitializeAPIInterface(this);
332334

333335
ui->setupUi(this);

UI/window-dock.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ void OBSDock::closeEvent(QCloseEvent *event)
3434
}
3535

3636
QDockWidget::closeEvent(event);
37+
38+
if (widget() && event->isAccepted()) {
39+
QEvent widgetEvent(QEvent::Type(QEvent::User + QEvent::Close));
40+
qApp->sendEvent(widget(), &widgetEvent);
41+
}
3742
}
3843

3944
void OBSDock::showEvent(QShowEvent *event)

docs/sphinx/reference-frontend-api.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,12 @@ Functions
480480
Adds a dock with the widget to the UI with a toggle in the Docks
481481
menu.
482482

483+
When the dock is closed, a custom QEvent of type `QEvent::User + QEvent::Close`
484+
is sent to the widget to enable it to react to the event (e.g., unload elements
485+
to save resources).
486+
A generic QShowEvent is already sent by default when the widget is being
487+
shown (e.g., dock opened).
488+
483489
Note: Use :c:func:`obs_frontend_remove_dock` to remove the dock
484490
and the id from the UI.
485491

0 commit comments

Comments
 (0)