diff options
author | Nicolas Werner <nicolas.werner@hotmail.de> | 2022-01-29 19:07:27 +0100 |
---|---|---|
committer | Nicolas Werner <nicolas.werner@hotmail.de> | 2022-01-29 19:07:27 +0100 |
commit | 392a4be858a9ba1d1870041f726e05501bf65c4e (patch) | |
tree | 298d57575e6888d8e7024ecf07af60b495f6298f /src/Utils.cpp | |
parent | Store window size on exit again (diff) | |
download | nheko-392a4be858a9ba1d1870041f726e05501bf65c4e.tar.xz |
Fix centering dialogs
Diffstat (limited to 'src/Utils.cpp')
-rw-r--r-- | src/Utils.cpp | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/src/Utils.cpp b/src/Utils.cpp index a9cfde22..0ac37d8e 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -17,6 +17,7 @@ #include <QStringBuilder> #include <QTextBoundaryFinder> #include <QTextDocument> +#include <QWindow> #include <QXmlStreamReader> #include <array> @@ -770,20 +771,17 @@ utils::luminance(const QColor &col) } void -utils::centerWidget(QWidget *widget, QWidget *parent) +utils::centerWidget(QWidget *widget, QWindow *parent) { - auto findCenter = [childRect = widget->rect()](QRect hostRect) -> QPoint { - return QPoint(hostRect.center().x() - (childRect.width() * 0.5), - hostRect.center().y() - (childRect.height() * 0.5)); - }; - if (parent) { - widget->move(parent->window()->frameGeometry().topLeft() + - parent->window()->rect().center() - widget->rect().center()); + widget->window()->windowHandle()->setTransientParent(parent); return; } - // Deprecated in 5.13: widget->move(findCenter(QApplication::desktop()->screenGeometry())); + auto findCenter = [childRect = widget->rect()](QRect hostRect) -> QPoint { + return QPoint(hostRect.center().x() - (childRect.width() * 0.5), + hostRect.center().y() - (childRect.height() * 0.5)); + }; widget->move(findCenter(QGuiApplication::primaryScreen()->geometry())); } |