Class: QgsCodeEditorPython¶
A Python editor based on QScintilla2. Adds syntax highlighting and code autocompletion.
Note
may not be available in Python bindings, depending on platform support

QgsCodeEditorPython containing sample Python¶
Class Hierarchy¶
Base classes¶
A text editor based on QScintilla2. |
|
Methods
Triggers the autocompletion popup. |
|
Returns the character after the cursor, or an empty string if the cursor is set at end |
|
Returns the character before the cursor, or an empty string if cursor is set at start |
|
Check whether the current cursor position is inside a string literal or a comment |
|
Load APIs from one or more files |
|
Loads a script file. |
|
Searches the selected text in the official PyQGIS online documentation. |
|
Toggle comment for the selected text. |
|
Updates the editor capabilities. |
- class qgis.gui.QgsCodeEditorPython[source]¶
Bases:
QgsCodeEditor
- __init__(parent: QWidget | None = None, filenames: Iterable[str | None] = [], mode: QgsCodeEditor.Mode = QgsCodeEditor.Mode.ScriptEditor, flags: QgsCodeEditor.Flags | QgsCodeEditor.Flag = QgsCodeEditor.Flag.CodeFolding)
Construct a new Python editor.
- Parameters:
parent (Optional[QWidget] = None) – The parent QWidget
filenames (Iterable[Optional[str]] = []) – The list of apis files to load for the Python lexer
mode (QgsCodeEditor.Mode = QgsCodeEditor.Mode.ScriptEditor) – code editor mode (since QGIS 3.30)
flags (Union[QgsCodeEditor.Flags, QgsCodeEditor.Flag] = QgsCodeEditor.Flag.CodeFolding) – code editor flags (since QGIS 3.32)
- characterAfterCursor(self) str [source]¶
Returns the character after the cursor, or an empty string if the cursor is set at end
Added in version 3.30.
- Return type:
str
- characterBeforeCursor(self) str [source]¶
Returns the character before the cursor, or an empty string if cursor is set at start
Added in version 3.30.
- Return type:
str
- isCursorInsideStringLiteralOrComment(self) bool [source]¶
Check whether the current cursor position is inside a string literal or a comment
Added in version 3.30.
- Return type:
bool
- loadAPIs(self, filenames: Iterable[str | None])[source]¶
Load APIs from one or more files
- Parameters:
filenames (Iterable[Optional[str]]) – The list of apis files to load for the Python lexer
- loadScript(self, script: str | None) bool [source]¶
Loads a
script
file.- Parameters:
script (Optional[str])
- Return type:
bool