summary refs log tree commit diff
path: root/src/Utils.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Utils.cpp')
-rw-r--r--src/Utils.cpp13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/Utils.cpp b/src/Utils.cpp

index 5feb5608..8ee6d5ae 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp
@@ -388,14 +388,15 @@ utils::linkColor() void utils::centerWidget(QWidget *widget, QWidget *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->geometry().center() - widget->rect().center()); + widget->move(findCenter(parent->geometry())); return; } - const QRect screenGeometry = QApplication::desktop()->screenGeometry(); - const int x = (screenGeometry.width() - widget->width()) / 2; - const int y = (screenGeometry.height() - widget->height()) / 2; - - widget->move(x, y); + widget->move(findCenter(QApplication::desktop()->screenGeometry())); }