Skip to content

Text editor with line counter and syntax highlighting

License

Notifications You must be signed in to change notification settings

leixingyu/codeEditor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Qt Code Editor

A PyQt5/PySide2 version of code editor with line counter and syntax highlighting

About The Project


code-editor

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.

Getting Started

Prerequisites

  • 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

Launch

  1. Unzip the qt-code-editor package and run main.py directly

  2. 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())

Reference

Qt Documentation - Code Editor Example

Qt for Python 6.2.2 - Code Editor Example

Python.org - Python syntax highlighting

About

Text editor with line counter and syntax highlighting

Topics

Resources

License

Stars

Watchers

Forks

Languages