diff --git a/nw/gui/elements/doceditor.py b/nw/gui/elements/doceditor.py index 906d4c65..082be79c 100644 --- a/nw/gui/elements/doceditor.py +++ b/nw/gui/elements/doceditor.py @@ -85,7 +85,8 @@ class GuiDocEditor(QTextEdit): # Document Title self.docTitle = GuiDocTitleBar(self, self.theProject) - self.docTitle.setGeometry(0,0,self.docTitle.width(),self.docTitle.height()) + self.docTitle.setGeometry(0, 0, self.docTitle.width(), self.docTitle.height()) + self.setViewportMargins(0, self.docTitle.height(), 0, 0) # Syntax self.hLight = GuiDocHighlighter(self.qDocument, self.theParent) @@ -336,13 +337,17 @@ class GuiDocEditor(QTextEdit): tB = self.lineWidth() tW = self.width() - 2*tB tH = self.docTitle.height() + tT = tM - tH self.docTitle.setGeometry(tB, tB, tW, tH) + self.setViewportMargins(0, tH, 0, 0) docFormat = self.qDocument.rootFrame().frameFormat() docFormat.setLeftMargin(tM) docFormat.setRightMargin(tM) - if docFormat.topMargin() < tH: - docFormat.setTopMargin(tH + 2) + if tT > 0: + docFormat.setTopMargin(tT) + else: + docFormat.setTopMargin(0) # Updating root frame triggers a QTextDocument->contentsChange # signal, which we do not want as it re-runs the syntax diff --git a/nw/gui/elements/docviewer.py b/nw/gui/elements/docviewer.py index 7fdf22e4..3ad0df6f 100644 --- a/nw/gui/elements/docviewer.py +++ b/nw/gui/elements/docviewer.py @@ -59,7 +59,8 @@ class GuiDocViewer(QTextBrowser): # Document Title self.docTitle = GuiDocTitleBar(self, self.theProject) - self.docTitle.setGeometry(0,0,self.docTitle.width(),self.docTitle.height()) + self.docTitle.setGeometry(0, 0, self.docTitle.width(), self.docTitle.height()) + self.setViewportMargins(0, self.docTitle.height(), 0, 0) theOpt = QTextOption() if self.mainConf.doJustify: @@ -218,11 +219,19 @@ class GuiDocViewer(QTextBrowser): tB = self.lineWidth() tW = self.width() - 2*tB tH = self.docTitle.height() + tT = self.mainConf.textMargin - tH self.docTitle.setGeometry(tB, tB, tW, tH) + self.setViewportMargins(0, tH, 0, 0) docFormat = self.qDocument.rootFrame().frameFormat() - if docFormat.topMargin() < tH: - docFormat.setTopMargin(tH + 2) + if tT > 0: + docFormat.setTopMargin(tT) + else: + docFormat.setTopMargin(0) + + self.qDocument.blockSignals(True) + self.qDocument.rootFrame().setFrameFormat(docFormat) + self.qDocument.blockSignals(False) return