From dec643e6ea167abc12be59f72e41756dd09ffb8d Mon Sep 17 00:00:00 2001 From: Konstantinos Sideris Date: Fri, 21 Sep 2018 16:44:45 +0300 Subject: v0.6.0 --- src/Utils.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'src/Utils.cpp') 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())); } -- cgit 1.5.1