Block main GUI from resizing to larger than the screen (#2369)

This commit is contained in:
Veronica Berglyd Olsen
2025-06-01 19:24:15 +02:00
committed by GitHub
2 changed files with 18 additions and 4 deletions
+11 -2
View File
@@ -38,7 +38,7 @@ from PyQt6.QtWidgets import (
) )
from novelwriter import CONFIG, SHARED, __hexversion__, __version__ from novelwriter import CONFIG, SHARED, __hexversion__, __version__
from novelwriter.common import formatFileFilter, formatVersion, hexToInt from novelwriter.common import formatFileFilter, formatVersion, hexToInt, minmax
from novelwriter.constants import nwConst from novelwriter.constants import nwConst
from novelwriter.dialogs.about import GuiAbout from novelwriter.dialogs.about import GuiAbout
from novelwriter.dialogs.preferences import GuiPreferences from novelwriter.dialogs.preferences import GuiPreferences
@@ -103,7 +103,7 @@ class GuiMain(QMainWindow):
SHARED.initSharedData(self) SHARED.initSharedData(self)
# Prepare Main Window # Prepare Main Window
self.resize(*CONFIG.mainWinSize) self._setWindowSize(CONFIG.mainWinSize)
self._updateWindowTitle() self._updateWindowTitle()
nwIcon = CONFIG.assetPath("icons") / "novelwriter.svg" nwIcon = CONFIG.assetPath("icons") / "novelwriter.svg"
@@ -1326,6 +1326,15 @@ class GuiMain(QMainWindow):
# Internal Functions # Internal Functions
## ##
def _setWindowSize(self, size: list[int]) -> None:
"""Set the main window size."""
if len(size) == 2 and (screen := SHARED.mainScreen):
availSize = screen.availableSize()
width = minmax(size[0], 900, availSize.width())
height = minmax(size[1], 500, availSize.height())
self.resize(width, height)
return
def _updateWindowTitle(self, projName: str | None = None) -> None: def _updateWindowTitle(self, projName: str | None = None) -> None:
"""Set the window title and add the project's name.""" """Set the window title and add the project's name."""
self.setWindowTitle(" - ".join(filter(None, [projName, CONFIG.appName]))) self.setWindowTitle(" - ".join(filter(None, [projName, CONFIG.appName])))
+7 -2
View File
@@ -32,8 +32,8 @@ from time import time
from typing import TYPE_CHECKING, TypeVar from typing import TYPE_CHECKING, TypeVar
from PyQt6.QtCore import QObject, QRunnable, QThreadPool, QTimer, QUrl, pyqtSignal, pyqtSlot from PyQt6.QtCore import QObject, QRunnable, QThreadPool, QTimer, QUrl, pyqtSignal, pyqtSlot
from PyQt6.QtGui import QDesktopServices, QFont from PyQt6.QtGui import QDesktopServices, QFont, QScreen
from PyQt6.QtWidgets import QFileDialog, QFontDialog, QMessageBox, QWidget from PyQt6.QtWidgets import QApplication, QFileDialog, QFontDialog, QMessageBox, QWidget
from novelwriter.common import formatFileFilter from novelwriter.common import formatFileFilter
from novelwriter.constants import nwFiles from novelwriter.constants import nwFiles
@@ -150,6 +150,11 @@ class SharedData(QObject):
"""Return the last alert message.""" """Return the last alert message."""
return self._lastAlert return self._lastAlert
@property
def mainScreen(self) -> QScreen | None:
"""Return the screen of the main window."""
return QApplication.screenAt(self.mainGui.rect().center())
## ##
# Setters # Setters
## ##