From 6672adf28773af771150dbe06081107a281f8284 Mon Sep 17 00:00:00 2001 From: pajlada Date: Tue, 2 May 2023 20:50:13 +0200 Subject: [PATCH] Fix the menu position on macOS when using Qt 6.5 (#4595) --- CHANGELOG.md | 6 +++++- src/widgets/helper/Button.cpp | 33 +++++++++++++++------------------ 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 91baaecce..bb0b11303 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,11 @@ ## Unversioned -## 2.4.3 +## Slated for 2.4.3 + +- Bugfix: Fixed the menu warping on macOS on Qt6. (#4595) + +## 2.4.3 Beta - Major: Added support for FrankerFaceZ animated emotes. (#4434) - Minor: Added the ability to reply to a message by `Shift + Right Click`ing the username. (#4424) diff --git a/src/widgets/helper/Button.cpp b/src/widgets/helper/Button.cpp index d1e92af97..a40dbf859 100644 --- a/src/widgets/helper/Button.cpp +++ b/src/widgets/helper/Button.cpp @@ -348,27 +348,24 @@ void Button::showMenu() if (!this->menu_) return; - auto point = [this] { - auto point = this->mapToGlobal( - QPoint(this->width() - this->menu_->width(), this->height())); + auto menuSizeHint = this->menu_->sizeHint(); + auto point = this->mapToGlobal( + QPoint(this->width() - menuSizeHint.width(), this->height())); - auto *screen = QApplication::screenAt(point); - if (screen == nullptr) - { - screen = QApplication::primaryScreen(); - } - auto bounds = screen->availableGeometry(); + auto *screen = QApplication::screenAt(point); + if (screen == nullptr) + { + screen = QApplication::primaryScreen(); + } + auto bounds = screen->availableGeometry(); - if (point.y() + this->menu_->height() > bounds.bottom()) - { - point.setY(point.y() - this->menu_->height() - this->height()); - } + if (point.y() + menuSizeHint.height() > bounds.bottom()) + { + // Menu doesn't fit going down, flip it to go up instead + point.setY(point.y() - menuSizeHint.height() - this->height()); + } - return point; - }; - - this->menu_->popup(point()); - this->menu_->move(point()); + this->menu_->popup(point); this->menuVisible_ = true; }