Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI,docs: Send a custom event to the dock widget when closing #10516

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions UI/window-basic-main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,8 @@ OBSBasic::OBSBasic(QWidget *parent)

setContextMenuPolicy(Qt::CustomContextMenu);

QEvent::registerEventType(QEvent::User + QEvent::Close);

api = InitializeAPIInterface(this);

ui->setupUi(this);
Expand Down
5 changes: 5 additions & 0 deletions UI/window-dock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ void OBSDock::closeEvent(QCloseEvent *event)
}

QDockWidget::closeEvent(event);

if (widget() && event->isAccepted()) {
QEvent widgetEvent(QEvent::Type(QEvent::User + QEvent::Close));
qApp->sendEvent(widget(), &widgetEvent);
}
}

void OBSDock::showEvent(QShowEvent *event)
Expand Down
6 changes: 6 additions & 0 deletions docs/sphinx/reference-frontend-api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,12 @@ Functions
Adds a dock with the widget to the UI with a toggle in the Docks
menu.

When the dock is closed, a custom QEvent of type `QEvent::User + QEvent::Close`
is sent to the widget to enable it to react to the event (e.g., unload elements
to save resources).
A generic QShowEvent is already sent by default when the widget is being
shown (e.g., dock opened).

Note: Use :c:func:`obs_frontend_remove_dock` to remove the dock
and the id from the UI.

Expand Down
Loading