diff options
author | Kenneth Mathis <kenneth.mathis99@gmail.com> | 2020-10-18 21:51:04 +0200 |
---|---|---|
committer | Kenneth Mathis <kenneth.mathis99@gmail.com> | 2020-10-18 21:51:04 +0200 |
commit | f99b045f39b39686d95319be52e195c6a00e3292 (patch) | |
tree | 727286503d9e507d03fe7bc8c8b7c169a56015ac | |
parent | cbce15c50bfa08644f3e84d18d9f44b91a9d8c89 (diff) |
Move MainWindow to the screen the cursor is on
-rw-r--r-- | main/main.cpp | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/main/main.cpp b/main/main.cpp index 31d92dbf..6456371f 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -6,6 +6,7 @@ #include <QApplication> #include <QDir> #include <QTranslator> +#include <QtWidgets> /*! \mainpage QtPass * @@ -101,6 +102,14 @@ int main(int argc, char *argv[]) { QGuiApplication::setDesktopFileName("qtpass.desktop"); #endif + + //Center the MainWindow on the screen the mouse pointer is currently on + static int cursorScreen = app.desktop()->screenNumber(app.desktop()->cursor().pos()); + QPoint cursorScreenCenter = app.desktop()->screenGeometry(cursorScreen).center(); + QRect windowFrameGeo = w.frameGeometry(); + windowFrameGeo.moveCenter(cursorScreenCenter); + w.move(windowFrameGeo.topLeft()); + w.show(); return SingleApplication::exec(); |