Qt: Cap window size to monitor size
Vicki Pfau vi@endrift.com
Fri, 26 Apr 2019 14:53:47 -0700
2 files changed,
13 insertions(+),
2 deletions(-)
M
src/platform/qt/Window.cpp
→
src/platform/qt/Window.cpp
@@ -5,14 +5,15 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "Window.h" -#include <QDesktopWidget> #include <QKeyEvent> #include <QKeySequence> #include <QMenuBar> #include <QMessageBox> #include <QMimeData> #include <QPainter> +#include <QScreen> #include <QStackedLayout> +#include <QWindow> #ifdef USE_SQLITE3 #include "ArchiveInspector.h"@@ -200,6 +201,15 @@ }
void Window::resizeFrame(const QSize& size) { QSize newSize(size); + if (windowHandle()) { + QRect geom = windowHandle()->screen()->availableGeometry(); + if (newSize.width() > geom.width()) { + newSize.setWidth(geom.width()); + } + if (newSize.height() > geom.height()) { + newSize.setHeight(geom.height()); + } + } m_screenWidget->setSizeHint(newSize); newSize -= m_screenWidget->size(); newSize += this->size();@@ -595,7 +605,7 @@ }
m_wasOpened = true; resizeFrame(m_screenWidget->sizeHint()); QVariant windowPos = m_config->getQtOption("windowPos"); - QRect geom = QApplication::desktop()->availableGeometry(this); + QRect geom = windowHandle()->screen()->availableGeometry(); if (!windowPos.isNull() && geom.contains(windowPos.toPoint())) { move(windowPos.toPoint()); } else {