This commit is contained in:
Konstantinos Sideris 2018-09-21 16:44:45 +03:00
parent 269519dfd9
commit dec643e6ea
7 changed files with 29 additions and 19 deletions

View file

@ -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()));
}