diff --git a/qt/aux_window.cpp b/qt/aux_window.cpp index 60b80dd..d5f3adb 100644 --- a/qt/aux_window.cpp +++ b/qt/aux_window.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include "aux_window.h" @@ -107,7 +108,16 @@ void AuxWindow::readSettings() QSize size = settings.value("size").toSize(); if (size.isValid()) resize(size); - move(settings.value("pos", QPoint(200, 200)).toPoint()); + const QRect &desktopRect = QApplication::desktop()->screenGeometry(); + QPoint point = settings.value("pos", QPoint(20, 20)).toPoint(); + // If the position was saved when an external monitor was plugged, and + // is restored when the monitor is not there anymore, the window could + // be off screen... + if (point.x() < 0 || point.x() > desktopRect.right()) + point.setX(20); + if (point.y() < 0 || point.y() > desktopRect.bottom()) + point.setY(20); + move(point); settings.endGroup(); } diff --git a/qt/main_window.cpp b/qt/main_window.cpp index 1ed4c8e..bfda5ea 100644 --- a/qt/main_window.cpp +++ b/qt/main_window.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include @@ -616,7 +617,16 @@ void MainWindow::readSettings() QSize size = settings.value("size").toSize(); if (size.isValid()) resize(size); - move(settings.value("pos", QPoint(200, 200)).toPoint()); + const QRect &desktopRect = QApplication::desktop()->screenGeometry(); + QPoint point = settings.value("pos", QPoint(20, 20)).toPoint(); + // If the position was saved when an external monitor was plugged, and + // is restored when the monitor is not there anymore, the window could + // be off screen... + if (point.x() < 0 || point.x() > desktopRect.right()) + point.setX(20); + if (point.y() < 0 || point.y() > desktopRect.bottom()) + point.setY(20); + move(point); m_ui.splitterHoriz->restoreState(settings.value("splitterHoriz").toByteArray()); m_ui.splitterVert->restoreState(settings.value("splitterVert").toByteArray()); settings.endGroup();