From 09b51badd40090091d4a82fcc4f790661d1da7fe Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Mon, 20 May 2024 11:17:23 +0200 Subject: [PATCH] Add an explicit font setting function for text editor that covers all font settings --- novelwriter/gui/doceditor.py | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/novelwriter/gui/doceditor.py b/novelwriter/gui/doceditor.py index bfd0be9a..3db8fca2 100644 --- a/novelwriter/gui/doceditor.py +++ b/novelwriter/gui/doceditor.py @@ -43,8 +43,8 @@ from PyQt5.QtCore import ( pyqtSignal, pyqtSlot ) from PyQt5.QtGui import ( - QColor, QCursor, QFont, QKeyEvent, QKeySequence, QMouseEvent, QPalette, - QPixmap, QResizeEvent, QTextBlock, QTextCursor, QTextDocument, QTextOption + QColor, QCursor, QKeyEvent, QKeySequence, QMouseEvent, QPalette, QPixmap, + QResizeEvent, QTextBlock, QTextCursor, QTextDocument, QTextOption ) from PyQt5.QtWidgets import ( QAction, QApplication, QFrame, QGridLayout, QHBoxLayout, QLabel, QLineEdit, @@ -329,10 +329,7 @@ class GuiDocEditor(QPlainTextEdit): SHARED.updateSpellCheckLanguage() # Set font - font = QFont() - font.setFamily(CONFIG.textFont) - font.setPointSize(CONFIG.textSize) - self._qDocument.setDefaultFont(font) + self.initFont() # Update highlighter settings self._qDocument.syntaxHighlighter.initHighlighter() @@ -382,6 +379,29 @@ class GuiDocEditor(QPlainTextEdit): return + def initFont(self) -> None: + """Set the font of the widget and document. This needs special + attention since there appears to be a bug in Qt 5.15.3. See + issues #1862 and #1875. + """ + wFont = self.font() + wFont.setFamily(CONFIG.textFont) + wFont.setPointSize(CONFIG.textSize) + + dFont = self._qDocument.defaultFont() + dFont.setFamily(CONFIG.textFont) + dFont.setPointSize(CONFIG.textSize) + + self.setFont(wFont) + self._qDocument.setDefaultFont(dFont) + + # Reset sub-widget font to GUI font + self.docHeader.setFont(SHARED.theme.guiFont) + self.docFooter.setFont(SHARED.theme.guiFont) + self.docSearch.setFont(SHARED.theme.guiFont) + + return + def loadText(self, tHandle: str, tLine: int | None = None) -> bool: """Load text from a document into the editor. If we have an I/O error, we must handle this and clear the editor so that we don't