I have anywhere an issue with the margin font size in combination with a lexer

Gottfried Müller gottfried.mueller at gmx.de
Sat Feb 6 13:21:18 GMT 2021


Hello,

when I change the lexer multiple times in an editor session I have an 
issue with the margin font size. Changing the lexer a second time the 
size of the margin font is changed. Only a point size of 9 in the editor 
has not any visual effects in the margin or editing area. I am working 
with the Manjaro distribution. There I have an default size of 10 points 
in my login sessions. Can anyone confirm this behaviour in Qscintilla?

Gottfried

Here is my code:

import sys
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QVBoxLayout
from PyQt5.QtGui import QFont
from PyQt5.Qsci import QsciScintilla, QsciLexerPython


class Editor(QsciScintilla):

     def __init__(self, parent=None):
         super().__init__(parent)
         self.fontMono = QFont("Monospace")
         self.fontMono.setPointSizeF(7.0)
         #self.fontMono.setPointSizeF(9.0)
         #self.fontMono.setPointSizeF(12.0)
         self.setFont(self.fontMono)
         self.setMarginsFont(self.fontMono)
         self.setMargins(1)
         self.setMarginType(0, QsciScintilla.NumberMargin)
         self.setMarginWidth(0, "0000")

     def useLexer(self, lexer):
         if lexer is not None:
             lexer.setFont(self.fontMono)
             lexer.setDefaultFont(self.fontMono)
         self.setMarginsFont(self.fontMono)
         self.setFont(self.fontMono)
         self.setLexer(lexer)


class ApplWindow(QWidget):

     def __init__(self, parent=None):
         super().__init__(parent)
         editor = Editor(parent=self)
         btn = QPushButton("Python", parent=self)
         layout = QVBoxLayout()
         layout.addWidget(btn)
         layout.addWidget(editor)
         self.setLayout(layout)
         with open(__file__, "r") as inp:
             text = inp.read()
         editor.append(text)
         editor.append(text)
         btn.pressed.connect(lambda: 
editor.useLexer(QsciLexerPython(parent=editor)))


def main():
     appl = QApplication(sys.argv)
     applWindow = ApplWindow()
     applWindow.show()
     return appl.exec_()


if __name__ == "__main__":
     main()



More information about the QScintilla mailing list