From d84779f12767085421b4859b1afd183ad64a0e9d Mon Sep 17 00:00:00 2001 From: nerix Date: Fri, 29 Dec 2023 14:20:07 +0100 Subject: [PATCH] fix: some buttons triggering when releasing mouse outside (#5052) Examples of buttons fixed with this: Usercard profile picture & split header mod mode button --- CHANGELOG.md | 1 + src/widgets/helper/Button.cpp | 13 +++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0c2bd123b..646d43713 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -57,6 +57,7 @@ - Bugfix: Fixed a bug on Wayland where tooltips would spawn as separate windows instead of behaving like tooltips. (#4998, #5040) - Bugfix: Fixes to section deletion in text input fields. (#5013) - Bugfix: Show user text input within watch streak notices. (#5029) +- Bugfix: Fixed avatar in usercard and moderation button triggering when releasing the mouse outside their area. (#5052) - Dev: Run miniaudio in a separate thread, and simplify it to not manage the device ourselves. There's a chance the simplification is a bad idea. (#4978) - Dev: Change clang-format from v14 to v16. (#4929) - Dev: Fixed UTF16 encoding of `modes` file for the installer. (#4791) diff --git a/src/widgets/helper/Button.cpp b/src/widgets/helper/Button.cpp index a6fa3ba6f..9b0a99abe 100644 --- a/src/widgets/helper/Button.cpp +++ b/src/widgets/helper/Button.cpp @@ -261,17 +261,26 @@ void Button::mousePressEvent(QMouseEvent *event) void Button::mouseReleaseEvent(QMouseEvent *event) { if (!this->enabled_) + { return; + } + + bool isInside = this->rect().contains(event->pos()); if (event->button() == Qt::LeftButton) { this->mouseDown_ = false; - if (this->rect().contains(event->pos())) + if (isInside) + { emit leftClicked(); + } } - emit clicked(event->button()); + if (isInside) + { + emit clicked(event->button()); + } } void Button::mouseMoveEvent(QMouseEvent *event)