Class: QgsCodeEditorWidget¶
A widget which wraps a QgsCodeEditor
in additional
functionality.
This widget wraps an existing QgsCodeEditor
object in a
widget which provides additional standard functionality, such as
search/replace tools. The caller must create an unparented
QgsCodeEditor
object (or a subclass of
QgsCodeEditor
) first, and then construct a
QgsCodeEditorWidget
passing this object to the constructor.
Note
may not be available in Python bindings, depending on platform support
Added in version 3.38.

QgsCodeEditorWidget containing a QgsCodeEditorPython editor¶

QgsCodeEditorWidget showing the search bar¶
Class Hierarchy¶
Base classes¶
Base class for any widget that can be shown as a inline panel |
|
Methods
Adds a warning message and indicator to the specified a lineNumber. |
|
Clears all warning messages from the editor. |
|
Returns the wrapped code editor. |
|
Returns the widget's associated file path. |
|
Hides the search bar. |
|
Returns |
|
Loads the file at the specified path into the widget, replacing the code editor's content with that from the file. |
|
Returns the message bar associated with the widget, to use for user feedback. |
|
Attempts to opens the script from the editor in an external text editor. |
|
Saves the code editor content into the file path. |
|
Returns the scrollbar highlight controller, which can be used to add highlights in the code editor scrollbar. |
|
Sets the widget's associated file path. |
|
Sets whether the replace bar is visible. |
|
Sets whether the search bar is visible. |
|
Shares the contents of the code editor on GitHub Gist. |
|
Shows the search bar. |
|
Triggers a find operation, using the default behavior. |
Signals
Emitted when the widget's associated file path is changed. |
|
Emitted when the widget loads in text from the associated file to bring in changes made externally to the file. |
|
Emitted when the visibility of the search bar is changed. |
- class qgis.gui.QgsCodeEditorWidget[source]¶
Bases:
QgsPanelWidget
- __init__(editor: QgsCodeEditor | None, messageBar: QgsMessageBar | None = None, parent: QWidget | None = None)
Constructor for QgsCodeEditorWidget, wrapping the specified
editor
widget.Ownership of
editor
will be transferred to this widget.If an explicit
messageBar
is specified then it will be used to provide feedback, otherwise an integrated message bar will be used.- Parameters:
editor (Optional[QgsCodeEditor])
messageBar (Optional[QgsMessageBar] = None)
parent (Optional[QWidget] = None)
- addWarning(self, lineNumber: int, warning: str | None)[source]¶
Adds a
warning
message and indicator to the specified alineNumber
.This method calls
QgsCodeEditor.addWarning()
, but also automatically adds highlights to the widget scrollbars locating the warning location.See also
- Parameters:
lineNumber (int)
warning (Optional[str])
- clearWarnings(self)[source]¶
Clears all warning messages from the editor.
This method calls
QgsCodeEditor.clearWarnings()
, but also removes highlights from the widget scrollbars at the warning locations.See also
- editor(self) QgsCodeEditor | None [source]¶
Returns the wrapped code editor.
- Return type:
Optional[QgsCodeEditor]
- filePath(self) str [source]¶
Returns the widget’s associated file path.
See also
See also
- Return type:
str
- signal filePathChanged(path: str)[source]¶
Emitted when the widget’s associated file path is changed.
See also
See also
- Parameters:
path (str)
- isSearchBarVisible(self) bool [source]¶
Returns
True
if the search bar is visible.- Return type:
bool
- loadFile(self, path: str | None) bool [source]¶
Loads the file at the specified
path
into the widget, replacing the code editor’s content with that from the file.This automatically sets the widget’s
filePath()
Returns
True
if the file was loaded successfully.- Parameters:
path (Optional[str])
- Return type:
bool
- signal loadedExternalChanges[source]¶
Emitted when the widget loads in text from the associated file to bring in changes made externally to the file.
- messageBar(self) QgsMessageBar | None [source]¶
Returns the message bar associated with the widget, to use for user feedback.
- Return type:
Optional[QgsMessageBar]
- openInExternalEditor(self, line: int = -1, column: int = -1) bool [source]¶
Attempts to opens the script from the editor in an external text editor.
This requires that the widget has an associated
filePath()
set.Optionally a target
line
andcolumn
number can be specified to open the editor at the corresponding location. (Not all external editors support this.) Line/column numbers of -1 indicate that the current cursor position should be used. Aline
number of 0 corresponds to the first line, and a column number of 0 corresponds to the first column.- Return type:
bool
- Returns:
True
if the file was opened successfully.- Parameters:
line (int = -1)
column (int = -1)
- save(self, path: str | None = '') bool [source]¶
Saves the code editor content into the file
path
.- Return type:
bool
- Returns:
False
if the file path has not previously been set, or if writing the file fails.
Note
When the path is empty, the content will be saved to the current file path if not empty.
Added in version 3.38.2.
- Parameters:
path (Optional[str] = '')
- scrollbarHighlightController(self) QgsScrollBarHighlightController | None [source]¶
Returns the scrollbar highlight controller, which can be used to add highlights in the code editor scrollbar.
- Return type:
Optional[QgsScrollBarHighlightController]
- signal searchBarToggled(visible: bool)[source]¶
Emitted when the visibility of the search bar is changed.
- Parameters:
visible (bool)
- setFilePath(self, path: str | None)[source]¶
Sets the widget’s associated file
path
.See also
See also
See also
- Parameters:
path (Optional[str])
- setReplaceBarVisible(self, visible: bool)[source]¶
Sets whether the replace bar is
visible
.See also
- Parameters:
visible (bool)
- setSearchBarVisible(self, visible: bool)[source]¶
Sets whether the search bar is
visible
.See also
See also
See also
- Parameters:
visible (bool)
Shares the contents of the code editor on GitHub Gist.
Requires that the user has configured an API token with appropriate permission in advance.
- Return type:
bool
- Returns:
False
if the user has not configured a GitHub personal access token.- Parameters:
isPublic (bool)