diff --git a/spinetoolbox/widgets/code_text_edit.py b/spinetoolbox/widgets/code_text_edit.py index cc115f7db..f8524d7e8 100644 --- a/spinetoolbox/widgets/code_text_edit.py +++ b/spinetoolbox/widgets/code_text_edit.py @@ -65,10 +65,11 @@ def setPlainText(self, text): self.setDocument(doc) def setDocument(self, doc): - doc.setDocumentLayout(QPlainTextDocumentLayout(doc)) + if doc is not None: + doc.setDocumentLayout(QPlainTextDocumentLayout(doc)) + doc.setDefaultFont(self.font()) super().setDocument(doc) self._highlighter.setDocument(doc) - doc.setDefaultFont(self.font()) self.setTabStopDistance(QFontMetrics(self.font()).horizontalAdvance(4 * " ")) def line_number_area_width(self):