Class: QgsCodeEditor¶
- class qgis.gui.QgsCodeEditor¶
Bases:
PyQt5.Qsci.QsciScintilla
A text editor based on QScintilla2.
Note
may not be available in Python bindings, depending on platform support
New in version 2.6.
QgsCodeEditor(parent: QWidget = None, title: str = ‘’, folding: bool = False, margin: bool = False, flags: Union[QgsCodeEditor.Flags, QgsCodeEditor.Flag] = QgsCodeEditor.Flags()) Construct a new code editor.
- Parameters:
parent – The parent QWidget
title – The title to show in the code editor dialog
folding –
False
: Enable folding for code editor (deprecated, useflags
instead)margin –
False
: Enable margin for code editor (deprecated)flags – flags controlling behavior of code editor (since QGIS 3.28)
New in version 2.6:
Enums
Bases:
enum.IntEnum
Bases:
enum.IntEnum
Methods
Adds a
warning
message and indicator to the specified alineNumber
.Clears all warning messages from the editor.
Returns the color to use in the editor for the specified
role
.Returns the default color for the specified
role
.- param watched:
- param event:
Returns
True
if the folding controls are visible in the editor.Returns the monospaced font to use for code editors.
Called when the dialect specific code lexer needs to be initialized (or reinitialized).
Insert text at cursor position, or replace any selected text if user has made a selection.
Returns
True
if the cursor is on the last line of the document.- param font:
- param event:
Returns the color to use in the lexer for the specified
role
.Returns the font to use in the lexer.
Returns whether line numbers are visible in the editor.
Returns whether margins are in a visible state
Moves the cursor to the end of the document and scrolls to ensure it is visible.
Moves the cursor to the start of the document and scrolls to ensure it is visible.
Performs tasks which must be run after a lexer has been set for the widget.
scrollContentsBy
Sets the
color
to use in the editor for the specifiedrole
.Set whether the folding controls are visible in the editor.
Sets whether line numbers should be visible in the editor.
Set margin visible state
Set the widget title
- class Flag(value)¶
Bases:
enum.IntEnum
Flags controlling behavior of code editor
New in version 3.28.
CodeFolding
: Indicates that code folding should be enabled for the editor
- CodeFolding = 1¶
- baseClass¶
alias of
QgsCodeEditor
- class Flags¶
- class Flags(Union[QgsCodeEditor.Flags, QgsCodeEditor.Flag])
- class Flags(QgsCodeEditor.Flags)
Bases:
sip.wrapper
- baseClass¶
alias of
QgsCodeEditor
- class MarginRole(value)¶
Bases:
enum.IntEnum
Margin roles.
This enum contains the roles which the different numbered margins are used for.
New in version 3.16.
LineNumbers
: Line numbersErrorIndicators
: Error indicatorsFoldingControls
: Folding controls
- baseClass¶
alias of
QgsCodeEditor
- actionEvent(self, QActionEvent)¶
- addWarning(self, lineNumber: int, warning: str)¶
Adds a
warning
message and indicator to the specified alineNumber
.See also
New in version 3.16.
- Parameters:
lineNumber (int) –
warning (str) –
- canInsertFromMimeData(self, QMimeData) bool ¶
- changeEvent(self, QEvent)¶
- childEvent(self, QChildEvent)¶
- clearWarnings(self)¶
Clears all warning messages from the editor.
See also
New in version 3.16.
- closeEvent(self, QCloseEvent)¶
- color(role: QgsCodeEditorColorScheme.ColorRole) QColor ¶
Returns the color to use in the editor for the specified
role
.This color will be the default theme color for the role, unless the user has manually selected a custom color scheme for the editor.
See also
New in version 3.16.
- Parameters:
role (QgsCodeEditorColorScheme.ColorRole) –
- Return type:
QColor
- connectNotify(self, QMetaMethod)¶
- contextMenuEvent(self, QContextMenuEvent)¶
- create(self, window: PyQt5.sip.voidptr = 0, initializeWindow: bool = True, destroyOldWindow: bool = True)¶
- customEvent(self, QEvent)¶
- defaultColor(role: QgsCodeEditorColorScheme.ColorRole, theme: str = '') QColor ¶
Returns the default color for the specified
role
.The optional
theme
argument can be used to specify a colortheme
. A blanktheme
indicates the default color scheme.Available themes are stored in
QgsCodeEditorColorSchemeRegistry
, and can be retrieved viaQgsGui.codeEditorColorSchemeRegistry()
.New in version 3.16.
- Parameters:
role (QgsCodeEditorColorScheme.ColorRole) –
theme (str = '') –
- Return type:
QColor
- destroy(self, destroyWindow: bool = True, destroySubWindows: bool = True)¶
- disconnectNotify(self, QMetaMethod)¶
- dragEnterEvent(self, QDragEnterEvent)¶
- dragLeaveEvent(self, QDragLeaveEvent)¶
- dragMoveEvent(self, QDragMoveEvent)¶
- drawFrame(self, QPainter)¶
- dropEvent(self, QDropEvent)¶
- enterEvent(self, QEvent)¶
- event(self, QEvent) bool ¶
- eventFilter(self, watched: QObject, event: QEvent) bool ¶
- Parameters:
watched (QObject) –
event (QEvent) –
- Return type:
bool
- focusInEvent(self, QFocusEvent)¶
- focusNextChild(self) bool ¶
- focusNextPrevChild(self, bool) bool ¶
- focusOutEvent(self, event: QFocusEvent)¶
- Parameters:
event (QFocusEvent) –
- focusPreviousChild(self) bool ¶
- foldingVisible(self) bool ¶
Returns
True
if the folding controls are visible in the editor.See also
- Return type:
bool
- fromMimeData(self, QMimeData) Tuple[QByteArray, bool] ¶
- getMonospaceFont() QFont ¶
Returns the monospaced font to use for code editors.
New in version 3.16.
- Return type:
QFont
- hideEvent(self, QHideEvent)¶
- initPainter(self, QPainter)¶
- initStyleOption(self, QStyleOptionFrame)¶
- initializeLexer(self)¶
Called when the dialect specific code lexer needs to be initialized (or reinitialized).
The default implementation does nothing.
New in version 3.16.
- inputMethodEvent(self, QInputMethodEvent)¶
- inputMethodQuery(self, Qt.InputMethodQuery) Any ¶
- insertText(self, text: str)¶
Insert text at cursor position, or replace any selected text if user has made a selection.
- Parameters:
text (str) – The text to be inserted
- isCursorOnLastLine(self) bool ¶
Returns
True
if the cursor is on the last line of the document.New in version 3.28.
- Return type:
bool
- isFixedPitch(self, font: QFont) bool ¶
- Parameters:
font (QFont) –
- Return type:
bool
- isSignalConnected(self, QMetaMethod) bool ¶
- keyPressEvent(self, event: QKeyEvent)¶
- Parameters:
event (QKeyEvent) –
- keyReleaseEvent(self, QKeyEvent)¶
- leaveEvent(self, QEvent)¶
- lexerColor(self, role: QgsCodeEditorColorScheme.ColorRole) QColor ¶
Returns the color to use in the lexer for the specified
role
.New in version 3.16.
- Parameters:
role (QgsCodeEditorColorScheme.ColorRole) –
- Return type:
QColor
- lexerFont(self) QFont ¶
Returns the font to use in the lexer.
New in version 3.16.
- Return type:
QFont
- lineNumbersVisible(self) bool ¶
Returns whether line numbers are visible in the editor.
See also
New in version 3.16.
- Return type:
bool
- marginVisible(self) bool ¶
Returns whether margins are in a visible state
Deprecated since version Use: base class methods for individual margins instead, or
lineNumbersVisible()
- Return type:
bool
- metric(self, QPaintDevice.PaintDeviceMetric) int ¶
- mouseDoubleClickEvent(self, QMouseEvent)¶
- mouseMoveEvent(self, QMouseEvent)¶
- mousePressEvent(self, QMouseEvent)¶
- mouseReleaseEvent(self, QMouseEvent)¶
- moveCursorToEnd(self)¶
Moves the cursor to the end of the document and scrolls to ensure it is visible.
New in version 3.28.
- moveCursorToStart(self)¶
Moves the cursor to the start of the document and scrolls to ensure it is visible.
New in version 3.28.
- moveEvent(self, QMoveEvent)¶
- nativeEvent(self, Union[QByteArray, bytes, bytearray], PyQt5.sip.voidptr) Tuple[bool, int] ¶
- paintEvent(self, QPaintEvent)¶
- receivers(self, PYQT_SIGNAL) int ¶
- resizeEvent(self, QResizeEvent)¶
- runPostLexerConfigurationTasks(self)¶
Performs tasks which must be run after a lexer has been set for the widget.
New in version 3.16.
- QgsCodeEditor.scrollContentsBy(self, int, int)
- sender(self) QObject ¶
- senderSignalIndex(self) int ¶
- setColor(role: QgsCodeEditorColorScheme.ColorRole, color: QColor | Qt.GlobalColor | QGradient)¶
Sets the
color
to use in the editor for the specifiedrole
.This color will be stored as the new default color for the role, to be used for all code editors.
Set
color
to an invalid QColor in order to clear the stored color value and reset it to the default color.See also
New in version 3.16.
- Parameters:
role (QgsCodeEditorColorScheme.ColorRole) –
color (Union[QColor) –
- setFoldingVisible(self, folding: bool)¶
Set whether the folding controls are visible in the editor.
See also
- Parameters:
folding (bool) –
- setLineNumbersVisible(self, visible: bool)¶
Sets whether line numbers should be visible in the editor.
Defaults to
False
.See also
New in version 3.16.
- Parameters:
visible (bool) –
- setMarginVisible(self, margin: bool)¶
Set margin visible state
- Parameters:
margin (bool) – Set margin in the editor
Deprecated since version Use: base class methods for individual margins instead, or
setLineNumbersVisible()
- setTitle(self, title: str)¶
Set the widget title
- Parameters:
title (str) – widget title
- QgsCodeEditor.setViewportMargins(self, int, int, int, int)
- setViewportMargins(self, QMargins) None ¶
- showEvent(self, QShowEvent)¶
- tabletEvent(self, QTabletEvent)¶
- timerEvent(self, QTimerEvent)¶
- toMimeData(self, Union[QByteArray, bytes, bytearray], bool) QMimeData ¶
- updateMicroFocus(self)¶
- viewportEvent(self, QEvent) bool ¶
- viewportMargins(self) QMargins ¶
- viewportSizeHint(self) QSize ¶
- wheelEvent(self, QWheelEvent)¶