A central repo to store useful stuff related to creating a code editor based on PyQt.
It currently consists of the main code editor subclassing from QPlainTextEdit
with
a side widget for line counter. It currently supports syntax highlighting for
.json
and .py
files, they are QSyntaxHighlighter
class which can be found
in the highlighter folder.
-
Qt: a module that supports different python qt bindings
or alternatively, change the code below to whatever qt binding you have on your machine.
from Qt import QtWidgets, QtCore, QtGui from Qt import _loadUi
-
Unzip the qt-code-editor package and run
main.py
directly -
Or include the following snippet to your ui code to create a code editor with syntax highlighting.
import codeEditor from highlighter.pyHighlight import PythonHighlighter editor = codeEditor.CodeEditor() highlighter = PythonHighlighter(editor.document())
Note: if you are using highlighter in a UI class, you'll need to keep an instance of the highlighter object like so:
self.__highlighter = PythonHighlighter(editor.document())
Qt Documentation - Code Editor Example