From ce26f041adf49d8281cf2248ef840313bc532dc5 Mon Sep 17 00:00:00 2001 From: Konstantinos Sideris Date: Fri, 21 Sep 2018 10:55:24 +0300 Subject: Add method to center widgets & clean up unused headers --- src/Utils.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/Utils.cpp') diff --git a/src/Utils.cpp b/src/Utils.cpp index 41be9e08..5feb5608 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -384,3 +384,18 @@ utils::linkColor() return QPalette().color(QPalette::Link).name(); } + +void +utils::centerWidget(QWidget *widget, QWidget *parent) +{ + if (parent) { + widget->move(parent->geometry().center() - widget->rect().center()); + 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); +} -- cgit 1.5.1