Class: QgisInterface

class qgis.gui.QgisInterface

Bases: PyQt5.QtCore.QObject

Constructor

QgisInterface Abstract base class defining interfaces exposed by QgisApp and made available to plugins.

Only functionality exposed by QgisInterface can be used in plugins. This interface has to be implemented with application specific details.

QGIS implements it in QgisAppInterface class, 3rd party applications could provide their own implementation to be able to use plugins.

Methods

actionAbout

rtype

QAction

actionAddAfsLayer

Returns the native Add ArcGIS FeatureServer action.

actionAddAllToOverview

rtype

QAction

actionAddAmsLayer

Returns the native Add ArcGIS MapServer action.

actionAddFeature

Returns the native Add Feature action.

actionAddOgrLayer

rtype

QAction

actionAddPart

Returns the native Add Part action.

actionAddPgLayer

rtype

QAction

actionAddRasterLayer

rtype

QAction

actionAddRing

Returns the native Add Ring action.

actionAddToOverview

rtype

QAction

actionAddWmsLayer

rtype

QAction

actionAllEdits

rtype

QAction

actionCancelAllEdits

rtype

QAction

actionCancelEdits

rtype

QAction

actionCheckQgisVersion

rtype

QAction

actionCopyFeatures

Returns the native Copy Features action.

actionCopyLayerStyle

rtype

QAction

actionCreatePrintLayout

Create new print layout action

actionCustomProjection

rtype

QAction

actionCutFeatures

Returns the native Cut Features action.

actionDeletePart

Returns the native Delete Part action.

actionDeleteRing

Returns the native Delete Ring action.

actionDeleteSelected

Returns the native Delete Selected Features action.

actionDraw

Returns the native draw action.

actionDuplicateLayer

rtype

QAction

actionExit

Returns the Exit QGIS action.

actionFeatureAction

Returns the native run action feature action.

actionHelpContents

rtype

QAction

actionHideAllLayers

rtype

QAction

actionHideDeselectedLayers

Returns the Hide Deselected Layers action.

actionHideSelectedLayers

rtype

QAction

actionIdentify

Returns the native identify action.

actionLayerProperties

rtype

QAction

actionLayerSaveAs

rtype

QAction

actionManagePlugins

rtype

QAction

actionMapTips

Returns the native map tips action.

actionMeasure

Returns the native measure action.

actionMeasureArea

Returns the native measure area action.

actionMoveFeature

Returns the native Move Features action.

actionNewBookmark

Returns the native new bookmark action.

actionNewProject

Returns the native New Project action.

actionNewVectorLayer

rtype

QAction

actionOpenFieldCalculator

rtype

QAction

actionOpenProject

Returns the Open Project action.

actionOpenStatisticalSummary

Statistical summary action.

actionOpenTable

rtype

QAction

actionOptions

rtype

QAction

actionPan

Returns the native pan action.

actionPanToSelected

Returns the native pan to selected action.

actionPasteFeatures

Returns the native Paste Features action.

actionPasteLayerStyle

rtype

QAction

actionPluginListSeparator

rtype

QAction

actionProjectProperties

Returns the native Project Properties action.

actionQgisHomePage

rtype

QAction

actionRemoveAllFromOverview

rtype

QAction

actionRollbackAllEdits

rtype

QAction

actionRollbackEdits

rtype

QAction

actionSaveActiveLayerEdits

rtype

QAction

actionSaveAllEdits

rtype

QAction

actionSaveEdits

rtype

QAction

actionSaveMapAsImage

Returns the native Save Map as Image action.

actionSaveProject

Returns the native Save Project action.

actionSaveProjectAs

Returns the native Save Project As action.

actionSelect

Returns the native select action.

actionSelectFreehand

Returns the native select freehand action.

actionSelectPolygon

Returns the native select polygon action.

actionSelectRadius

Returns the native select radius action.

actionSelectRectangle

Returns the native select rectangle action.

actionShowAllLayers

rtype

QAction

actionShowBookmarks

Returns the native show bookmarks action.

actionShowLayoutManager

Show layout manager action

actionShowPythonDialog

rtype

QAction

actionShowSelectedLayers

rtype

QAction

actionSimplifyFeature

Returns the native Simplify/Smooth Features action.

actionSplitFeatures

Returns the native Split Features action.

actionSplitParts

Returns the native Split Parts action.

actionToggleEditing

rtype

QAction

actionToggleFullScreen

rtype

QAction

actionVertexTool

Returns the native Vertex Tool action.

actionZoomActualSize

Returns the native zoom resolution (100%) action.

actionZoomFullExtent

Returns the native zoom full extent action.

actionZoomIn

Returns the native zoom in action.

actionZoomLast

Returns the native zoom last action.

actionZoomNext

Returns the native zoom next action.

actionZoomOut

Returns the native zoom out action.

actionZoomToLayer

Returns the native zoom to layer action.

actionZoomToSelected

Returns the native zoom to selected action.

activeLayer

Returns a pointer to the active layer (layer selected in the legend)

addCustomActionForLayer

Add action to context menu for a specific layer in the layer tree.

addCustomActionForLayerType

Add action to context menu for layers in the layer tree.

addDatabaseToolBarIcon

Add an icon to the Database toolbar

addDatabaseToolBarWidget

Add a widget to the database toolbar.

addDockWidget

Adds a dock widget to the main window, in the specified dock area.

addLayerMenu

Returns a reference to the main window “Add Layer” menu.

addMeshLayer

Adds a mesh layer to the current project.

addPluginToDatabaseMenu

Add action to the Database menu

addPluginToMenu

Add action to the plugins menu

addPluginToRasterMenu

Add action to the Raster menu

addPluginToVectorMenu

Add action to the Vector menu

addPluginToWebMenu

Add action to the Web menu

addProject

Adds (opens) a project

addRasterLayer

Adds a raster layer to the current project, given a raster layer file name.

addRasterToolBarIcon

Add an icon to the Raster toolbar

addRasterToolBarWidget

Add a widget to the raster toolbar.

addToolBar

Add toolbar with specified name

addToolBarIcon

Add an icon to the plugins toolbar

addToolBarWidget

Add a widget to the plugins toolbar.

addUserInputWidget

Adds a widget to the user input tool bar.

addVectorLayer

Adds a vector layer to the current project.

addVectorToolBarIcon

Add an icon to the Vector toolbar

addVectorToolBarWidget

Add a widget to the vector toolbar.

addWebToolBarIcon

Add an icon to the Web toolbar

addWebToolBarWidget

Add a widget to the web toolbar.

addWindow

Add window to Window menu.

advancedDigitizeToolBar

Returns a reference to the main window “Advanced Digitizing” toolbar.

askForDatumTransform

Checks available datum transforms and ask user if several are available and none is chosen.

attributesToolBar

Returns a reference to the main window “Attributes” toolbar.

browserModel

Returns the application browser model.

buildStyleSheet

Generate stylesheet

cadDockWidget

Advanced digitizing dock widget

childEvent

closeMapCanvas

Closes the additional map canvas with matching name.

connectNotify

copySelectionToClipboard

Copy selected features from the layer to clipboard

createNewMapCanvas

Create a new map canvas with the specified unique name.

customEvent

dataSourceManagerToolBar

Returns a reference to the main window “Data Source Manager” toolbar.

databaseMenu

Returns a reference to the main window “Database” menu.

databaseToolBar

Returns a reference to the main window “Database” toolbar.

defaultStyleSheetFont

Returns a reference font for initial qApp (may not be same as QgisApp)

defaultStyleSheetOptions

Returns changeable options built from settings and/or defaults

deregisterLocatorFilter

Deregisters a locator filter from the app’s locator bar and deletes it.

digitizeToolBar

Returns a reference to the main window “Digitize” toolbar.

disconnectNotify

editMenu

Returns a reference to the main window “Edit” menu.

editableLayers

Returns vector layers in edit mode

fileToolBar

Returns a reference to the main window “File” toolbar.

firstRightStandardMenu

Returns a reference to the right most standard menu, which is usually the last menu item before the “Help” menu.

getFeatureForm

Returns a feature form for a given feature.

helpMenu

Returns a reference to the main window “Help” menu.

helpToolBar

Returns a reference to the main window “Help” toolbar.

iconSize

Returns the toolbar icon size.

insertAddLayerAction

Add “add layer” action to layer menu

invalidateLocatorResults

Invalidate results from the locator filter.

isSignalConnected

layerMenu

Returns a reference to the main window “Layer” menu.

layerToolBar

Returns a reference to the main window “Layer” toolbar.

layerTreeCanvasBridge

Returns a pointer to the layer tree canvas bridge

layerTreeView

rtype

QgsLayerTreeView

mainWindow

Returns a pointer to the main window (instance of QgisApp in case of QGIS)

mapCanvas

Returns a pointer to the map canvas

mapCanvases

Returns a list of all map canvases open in the app.

mapNavToolToolBar

Returns a reference to the main window “Map Navigation” toolbar.

messageBar

Returns the message bar of the main app

messageTimeout

Returns the timeout for timed messages: default of 5 seconds

newLayerMenu

Returns a reference to the main window “Create New Layer” menu.

newProject

Starts a new blank project

openFeatureForm

Opens a new feature form.

openLayoutDesigner

Opens a new layout designer dialog for the specified layout, or brings an already open designer window to the foreground if one is already created for the layout.

openLayoutDesigners

Returns all currently open layout designers.

openMessageLog

Opens the message log dock widget.

openURL

Open a url in the users browser.

pasteFromClipboard

Paste features from clipboard to the layer

pluginManagerInterface

rtype

QgsPluginManagerInterface

pluginMenu

Returns a reference to the main window “Plugin” menu.

pluginToolBar

Returns a reference to the main window “Plugin” toolbar.

preloadForm

This method is only needed when using a UI form with a custom widget plugin and calling openFeatureForm or getFeatureForm from Python (PyQt) and you haven’t used the info tool first.

projectMenu

Returns a reference to the main window “Project” menu.

rasterMenu

Returns a reference to the main window “Raster” menu.

rasterToolBar

Returns a reference to the main window “Raster” toolbar.

receivers

registerCustomDropHandler

Register a new custom drop handler.

registerCustomLayoutDropHandler

Register a new custom drop handler for layout windows.

registerLocatorFilter

Registers a locator filter for the app’s locator bar.

registerMainWindowAction

Register action to the shortcuts manager so its shortcut can be changed in GUI

registerMapLayerConfigWidgetFactory

Register a new tab in the vector layer properties dialog.

registerOptionsWidgetFactory

Register a new tab in the options dialog.

reloadConnections

Triggered when connections have changed.

removeAddLayerAction

Remove “add layer” action from layer menu

removeCustomActionForLayerType

Remove action for layers in the layer tree previously added with addCustomActionForLayerType()

removeDatabaseToolBarIcon

Remove an action (icon) from the Database toolbar

removeDockWidget

Removes the specified dock widget from main window (without deleting it).

removePluginDatabaseMenu

Remove action from the Database menu

removePluginMenu

Remove action from the plugins menu

removePluginRasterMenu

Remove action from the Raster menu

removePluginVectorMenu

Remove action from the Vector menu

removePluginWebMenu

Remove action from the Web menu

removeRasterToolBarIcon

Remove an action (icon) from the Raster toolbar

removeToolBarIcon

Remove an action (icon) from the plugin toolbar

removeVectorToolBarIcon

Remove an action (icon) from the Vector toolbar

removeWebToolBarIcon

Remove an action (icon) from the Web toolbar

removeWindow

Remove window from Window menu.

saveStyleSheetOptions

Save changed default option keys/values to user settings

sender

senderSignalIndex

setActiveLayer

Set the active layer (layer gets selected in the legend) returns true if the layer exists, false otherwise

settingsMenu

Returns a reference to the main window “Settings” menu.

shapeDigitizeToolBar

Returns a reference to the main window “Shape Digitizing” toolbar.

showAttributeTable

Open attribute table dialog

showLayerProperties

Open layer properties dialog

showLayoutManager

Opens the layout manager dialog.

showOptionsDialog

Opens the options dialog.

statusBarIface

Returns a pointer to the app’s status bar interface.

takeAppScreenShots

Take screenshots for user documentation @param saveDirectory path where the screenshots will be saved @param categories an int as a flag value of QgsAppScreenShots.Categories

timerEvent

unregisterCustomDropHandler

Unregister a previously registered custom drop handler.

unregisterCustomLayoutDropHandler

Unregister a previously registered custom drop handler for layout windows.

unregisterMainWindowAction

Unregister a previously registered action.

unregisterMapLayerConfigWidgetFactory

Unregister a previously registered tab in the vector layer properties dialog.

unregisterOptionsWidgetFactory

Unregister a previously registered tab in the options dialog.

vectorLayerTools

Access the vector layer tools instance.

vectorMenu

Returns a reference to the main window “Vector” menu.

vectorToolBar

Returns a reference to the main window “Vector” toolbar.

viewMenu

Returns a reference to the main window “View” menu.

webMenu

Returns a reference to the main window “Web” menu.

webToolBar

Returns a reference to the main window “Web” toolbar.

windowMenu

Returns a reference to the main window “Window” menu.

zoomFull

Zooms to the full extent of all map layers.

zoomToActiveLayer

Zooms to extent of the active layer.

zoomToNext

Zooms to the next view extent.

zoomToPrevious

Zooms to the previous view extent.

Signals

currentLayerChanged

Emitted whenever current (selected) layer changes.

currentThemeChanged

Signal emitted when the current theme is changed so plugins can change their tool button icons.

initializationCompleted

This signal is emitted when the initialization is complete.

layerSavedAs

This signal is emitted when a layer has been saved using save as.

layoutDesignerClosed

This signal is emitted after a layout designer window is closed.

layoutDesignerOpened

This signal is emitted when a new layout designer has been opened.

layoutDesignerWillBeClosed

This signal is emitted before a layout designer is going to be closed and deleted.

newProjectCreated

Emitted when starting an entirely new project.

projectRead

Emitted when a project file is successfully read.

actionAbout(self) → QAction
Return type

QAction

actionAddAfsLayer(self) → QAction

Returns the native Add ArcGIS FeatureServer action.

Return type

QAction

actionAddAllToOverview(self) → QAction
Return type

QAction

actionAddAmsLayer(self) → QAction

Returns the native Add ArcGIS MapServer action.

Return type

QAction

actionAddFeature(self) → QAction

Returns the native Add Feature action.

Return type

QAction

actionAddOgrLayer(self) → QAction
Return type

QAction

actionAddPart(self) → QAction

Returns the native Add Part action.

Return type

QAction

actionAddPgLayer(self) → QAction
Return type

QAction

actionAddRasterLayer(self) → QAction
Return type

QAction

actionAddRing(self) → QAction

Returns the native Add Ring action.

Return type

QAction

actionAddToOverview(self) → QAction
Return type

QAction

actionAddWmsLayer(self) → QAction
Return type

QAction

actionAllEdits(self) → QAction
Return type

QAction

actionCancelAllEdits(self) → QAction
Return type

QAction

actionCancelEdits(self) → QAction
Return type

QAction

actionCheckQgisVersion(self) → QAction
Return type

QAction

actionCopyFeatures(self) → QAction

Returns the native Copy Features action.

Return type

QAction

actionCopyLayerStyle(self) → QAction
Return type

QAction

actionCreatePrintLayout(self) → QAction

Create new print layout action

Return type

QAction

actionCustomProjection(self) → QAction
Return type

QAction

actionCutFeatures(self) → QAction

Returns the native Cut Features action.

Return type

QAction

actionDeletePart(self) → QAction

Returns the native Delete Part action.

Return type

QAction

actionDeleteRing(self) → QAction

Returns the native Delete Ring action.

Return type

QAction

actionDeleteSelected(self) → QAction

Returns the native Delete Selected Features action.

Return type

QAction

actionDraw(self) → QAction

Returns the native draw action.

Return type

QAction

actionDuplicateLayer(self) → QAction
Return type

QAction

actionExit(self) → QAction

Returns the Exit QGIS action.

Return type

QAction

actionFeatureAction(self) → QAction

Returns the native run action feature action. Call trigger() on it to set the default run feature action map tool.

Return type

QAction

actionHelpContents(self) → QAction
Return type

QAction

actionHideAllLayers(self) → QAction
Return type

QAction

actionHideDeselectedLayers(self) → QAction

Returns the Hide Deselected Layers action.

New in version 3.0.

Return type

QAction

actionHideSelectedLayers(self) → QAction
Return type

QAction

actionIdentify(self) → QAction

Returns the native identify action. Call trigger() on it to set the default identify map tool.

Return type

QAction

actionLayerProperties(self) → QAction
Return type

QAction

actionLayerSaveAs(self) → QAction
Return type

QAction

actionManagePlugins(self) → QAction
Return type

QAction

actionMapTips(self) → QAction

Returns the native map tips action. Call trigger() on it to toggle map tips.

Return type

QAction

actionMeasure(self) → QAction

Returns the native measure action. Call trigger() on it to set the default measure map tool.

Return type

QAction

actionMeasureArea(self) → QAction

Returns the native measure area action. Call trigger() on it to set the default measure area map tool.

Return type

QAction

actionMoveFeature(self) → QAction

Returns the native Move Features action.

Return type

QAction

actionNewBookmark(self) → QAction

Returns the native new bookmark action. Call trigger() on it to open the new bookmark dialog.

Return type

QAction

actionNewProject(self) → QAction

Returns the native New Project action.

Return type

QAction

actionNewVectorLayer(self) → QAction
Return type

QAction

actionOpenFieldCalculator(self) → QAction
Return type

QAction

actionOpenProject(self) → QAction

Returns the Open Project action.

Return type

QAction

actionOpenStatisticalSummary(self) → QAction

Statistical summary action.

New in version 3.0.

Return type

QAction

actionOpenTable(self) → QAction
Return type

QAction

actionOptions(self) → QAction
Return type

QAction

actionPan(self) → QAction

Returns the native pan action. Call trigger() on it to set the default pan map tool.

Return type

QAction

actionPanToSelected(self) → QAction

Returns the native pan to selected action. Call trigger() on it to pan the map canvas to the selection.

Return type

QAction

actionPasteFeatures(self) → QAction

Returns the native Paste Features action.

Return type

QAction

actionPasteLayerStyle(self) → QAction
Return type

QAction

actionPluginListSeparator(self) → QAction
Return type

QAction

actionProjectProperties(self) → QAction

Returns the native Project Properties action.

Return type

QAction

actionQgisHomePage(self) → QAction
Return type

QAction

actionRemoveAllFromOverview(self) → QAction
Return type

QAction

actionRollbackAllEdits(self) → QAction
Return type

QAction

actionRollbackEdits(self) → QAction
Return type

QAction

actionSaveActiveLayerEdits(self) → QAction
Return type

QAction

actionSaveAllEdits(self) → QAction
Return type

QAction

actionSaveEdits(self) → QAction
Return type

QAction

actionSaveMapAsImage(self) → QAction

Returns the native Save Map as Image action.

Return type

QAction

actionSaveProject(self) → QAction

Returns the native Save Project action.

Return type

QAction

actionSaveProjectAs(self) → QAction

Returns the native Save Project As action.

Return type

QAction

actionSelect(self) → QAction

Returns the native select action. Call trigger() on it to set the default select map tool.

Return type

QAction

actionSelectFreehand(self) → QAction

Returns the native select freehand action. Call trigger() on it to set the default select freehand map tool.

Return type

QAction

actionSelectPolygon(self) → QAction

Returns the native select polygon action. Call trigger() on it to set the default select polygon map tool.

Return type

QAction

actionSelectRadius(self) → QAction

Returns the native select radius action. Call trigger() on it to set the default select radius map tool.

Return type

QAction

actionSelectRectangle(self) → QAction

Returns the native select rectangle action. Call trigger() on it to set the default select rectangle map tool.

Return type

QAction

actionShowAllLayers(self) → QAction
Return type

QAction

actionShowBookmarks(self) → QAction

Returns the native show bookmarks action. Call trigger() on it to open the bookmarks dialog.

Return type

QAction

actionShowLayoutManager(self) → QAction

Show layout manager action

Return type

QAction

actionShowPythonDialog(self) → QAction
Return type

QAction

actionShowSelectedLayers(self) → QAction
Return type

QAction

actionSimplifyFeature(self) → QAction

Returns the native Simplify/Smooth Features action.

Return type

QAction

actionSplitFeatures(self) → QAction

Returns the native Split Features action.

Return type

QAction

actionSplitParts(self) → QAction

Returns the native Split Parts action.

Return type

QAction

actionToggleEditing(self) → QAction
Return type

QAction

actionToggleFullScreen(self) → QAction
Return type

QAction

actionVertexTool(self) → QAction

Returns the native Vertex Tool action.

Return type

QAction

actionZoomActualSize(self) → QAction

Returns the native zoom resolution (100%) action. Call trigger() on it to zoom to actual size.

Return type

QAction

actionZoomFullExtent(self) → QAction

Returns the native zoom full extent action. Call trigger() on it to zoom to the full extent.

Return type

QAction

actionZoomIn(self) → QAction

Returns the native zoom in action. Call trigger() on it to set the default zoom in map tool.

Return type

QAction

actionZoomLast(self) → QAction

Returns the native zoom last action. Call trigger() on it to zoom to last.

Return type

QAction

actionZoomNext(self) → QAction

Returns the native zoom next action. Call trigger() on it to zoom to next.

Return type

QAction

actionZoomOut(self) → QAction

Returns the native zoom out action. Call trigger() on it to set the default zoom out map tool.

Return type

QAction

actionZoomToLayer(self) → QAction

Returns the native zoom to layer action. Call trigger() on it to zoom to the active layer.

Return type

QAction

actionZoomToSelected(self) → QAction

Returns the native zoom to selected action. Call trigger() on it to zoom to the current selection.

Return type

QAction

activeLayer(self) → QgsMapLayer

Returns a pointer to the active layer (layer selected in the legend)

Return type

QgsMapLayer

addCustomActionForLayer(self, action: QAction, layer: QgsMapLayer)

Add action to context menu for a specific layer in the layer tree. It is necessary to first call addCustomActionForLayerType() with allLayers=false in order for this method to have any effect.

Parameters
addCustomActionForLayerType(self, action: QAction, menu: str, type: QgsMapLayer.LayerType, allLayers: bool)

Add action to context menu for layers in the layer tree. If allLayers is true, then the action will be available for all layers of given type, otherwise the action will be available only for specific layers added with addCustomActionForLayer() after this call.

If menu argument is not empty, the action will be also added to a menu within the main window, creating menu with the given name if it does not exist yet.

Parameters
addDatabaseToolBarIcon(self, qAction: QAction) → int

Add an icon to the Database toolbar

Parameters

qAction (QAction) –

Return type

int

addDatabaseToolBarWidget(self, widget: QWidget) → QAction

Add a widget to the database toolbar. To remove this widget again, call removeDatabaseToolBarIcon() with the returned QAction.

Parameters

widget (QWidget) – widget to add. The toolbar will take ownership of this widget

Return type

QAction

Returns

the QAction you can use to remove this widget from the toolbar

addDockWidget(self, area: Qt.DockWidgetArea, dockwidget: QDockWidget)

Adds a dock widget to the main window, in the specified dock area.

Parameters
  • area (Qt.DockWidgetArea) –

  • dockwidget (QDockWidget) –

addLayerMenu(self) → QMenu

Returns a reference to the main window “Add Layer” menu.

New in version 2.5.

Return type

QMenu

addMeshLayer(self, url: str, baseName: str, providerKey: str) → QgsMeshLayer

Adds a mesh layer to the current project.

Parameters
  • url (str) –

  • baseName (str) –

  • providerKey (str) –

Return type

QgsMeshLayer

addPluginToDatabaseMenu(self, name: str, action: QAction)

Add action to the Database menu

Parameters
  • name (str) –

  • action (QAction) –

addPluginToMenu(self, name: str, action: QAction)

Add action to the plugins menu

Parameters
  • name (str) –

  • action (QAction) –

addPluginToRasterMenu(self, name: str, action: QAction)

Add action to the Raster menu

Parameters
  • name (str) –

  • action (QAction) –

addPluginToVectorMenu(self, name: str, action: QAction)

Add action to the Vector menu

Parameters
  • name (str) –

  • action (QAction) –

addPluginToWebMenu(self, name: str, action: QAction)

Add action to the Web menu

Parameters
  • name (str) –

  • action (QAction) –

addProject(self, project: str) → bool

Adds (opens) a project

Parameters

project (str) –

Return type

bool

addRasterLayer(self, rasterLayerPath: str, baseName: str = '') → QgsRasterLayer

Adds a raster layer to the current project, given a raster layer file name.

addRasterLayer(self, url: str, layerName: str, providerKey: str) -> QgsRasterLayer Adds a raster layer to the current project, from the specified raster data provider.

Parameters
  • rasterLayerPath (str) –

  • baseName (str = '') –

Return type

QgsRasterLayer

addRasterToolBarIcon(self, qAction: QAction) → int

Add an icon to the Raster toolbar

Parameters

qAction (QAction) –

Return type

int

addRasterToolBarWidget(self, widget: QWidget) → QAction

Add a widget to the raster toolbar. To remove this widget again, call removeRasterToolBarIcon() with the returned QAction.

Parameters

widget (QWidget) – widget to add. The toolbar will take ownership of this widget

Return type

QAction

Returns

the QAction you can use to remove this widget from the toolbar

addToolBar(self, name: str) → QToolBar

Add toolbar with specified name

addToolBar(self, toolbar: QToolBar, area: Qt.ToolBarArea = Qt.TopToolBarArea) Add a toolbar

New in version 2.3.

Parameters

name (str) –

Return type

QToolBar

addToolBarIcon(self, qAction: QAction) → int

Add an icon to the plugins toolbar

Parameters

qAction (QAction) –

Return type

int

addToolBarWidget(self, widget: QWidget) → QAction

Add a widget to the plugins toolbar. To remove this widget again, call removeToolBarIcon() with the returned QAction.

Parameters

widget (QWidget) – widget to add. The toolbar will take ownership of this widget

Return type

QAction

Returns

the QAction you can use to remove this widget from the toolbar

addUserInputWidget(self, widget: QWidget)

Adds a widget to the user input tool bar.

Parameters

widget (QWidget) –

addVectorLayer(self, vectorLayerPath: str, baseName: str, providerKey: str) → QgsVectorLayer

Adds a vector layer to the current project.

Parameters
  • vectorLayerPath (str) –

  • baseName (str) –

  • providerKey (str) –

Return type

QgsVectorLayer

addVectorToolBarIcon(self, qAction: QAction) → int

Add an icon to the Vector toolbar

Parameters

qAction (QAction) –

Return type

int

addVectorToolBarWidget(self, widget: QWidget) → QAction

Add a widget to the vector toolbar. To remove this widget again, call removeVectorToolBarIcon() with the returned QAction.

Parameters

widget (QWidget) – widget to add. The toolbar will take ownership of this widget

Return type

QAction

Returns

the QAction you can use to remove this widget from the toolbar

addWebToolBarIcon(self, qAction: QAction) → int

Add an icon to the Web toolbar

Parameters

qAction (QAction) –

Return type

int

addWebToolBarWidget(self, widget: QWidget) → QAction

Add a widget to the web toolbar. To remove this widget again, call removeWebToolBarIcon() with the returned QAction.

Parameters

widget (QWidget) – widget to add. The toolbar will take ownership of this widget

Return type

QAction

Returns

the QAction you can use to remove this widget from the toolbar

addWindow(self, action: QAction)

Add window to Window menu. The action title is the window title and the action should raise, unminimize and activate the window. *

Parameters

action (QAction) –

advancedDigitizeToolBar(self) → QToolBar

Returns a reference to the main window “Advanced Digitizing” toolbar.

Return type

QToolBar

askForDatumTransform(self, sourceCrs: QgsCoordinateReferenceSystem, destinationCrs: QgsCoordinateReferenceSystem) → bool

Checks available datum transforms and ask user if several are available and none is chosen. Dialog is shown only if global option is set accordingly.

Return type

bool

Returns

true if a datum transform has been specifically chosen by user or only one is available.

New in version 3.0.

Parameters
attributesToolBar(self) → QToolBar

Returns a reference to the main window “Attributes” toolbar.

Return type

QToolBar

browserModel(self) → QgsBrowserModel

Returns the application browser model. Using this shared model is more efficient than creating a new browser model for every use.

New in version 3.4.

Return type

QgsBrowserModel

buildStyleSheet(self, opts: Dict[str, Any])

Generate stylesheet

Parameters

opts (Dict[str) – generated default option values, or a changed copy of them

cadDockWidget(self) → QgsAdvancedDigitizingDockWidget

Advanced digitizing dock widget

New in version 2.12.

Return type

QgsAdvancedDigitizingDockWidget

childEvent()
closeMapCanvas(self, name: str)

Closes the additional map canvas with matching name.

New in version 3.0.

Parameters

name (str) –

connectNotify()
copySelectionToClipboard(self, QgsMapLayer)

Copy selected features from the layer to clipboard

New in version 3.0.

createNewMapCanvas(self, name: str) → QgsMapCanvas

Create a new map canvas with the specified unique name.

See also

closeMapCanvas()

New in version 3.0.

Parameters

name (str) –

Return type

QgsMapCanvas

currentLayerChanged

Emitted whenever current (selected) layer changes. The pointer to layer can be null if no layer is selected. [signal]

currentThemeChanged

Signal emitted when the current theme is changed so plugins can change their tool button icons.

New in version 3.0: [signal]

customEvent()
dataSourceManagerToolBar(self) → QToolBar

Returns a reference to the main window “Data Source Manager” toolbar.

New in version 3.4.

Return type

QToolBar

databaseMenu(self) → QMenu

Returns a reference to the main window “Database” menu.

Return type

QMenu

databaseToolBar(self) → QToolBar

Returns a reference to the main window “Database” toolbar.

Return type

QToolBar

defaultStyleSheetFont(self) → QFont

Returns a reference font for initial qApp (may not be same as QgisApp)

Return type

QFont

defaultStyleSheetOptions(self) → Dict[str, Any]

Returns changeable options built from settings and/or defaults

Return type

Dict[str, Any]

deregisterLocatorFilter(self, filter: QgsLocatorFilter)

Deregisters a locator filter from the app’s locator bar and deletes it. Calling this will block whilst any currently running query is terminated.

Plugins which register filters to the locator bar must take care to correctly call deregisterLocatorFilter() to deregister their filters upon plugin unload to avoid crashes.

New in version 3.0.

Parameters

filter (QgsLocatorFilter) –

digitizeToolBar(self) → QToolBar

Returns a reference to the main window “Digitize” toolbar.

Return type

QToolBar

disconnectNotify()
editMenu(self) → QMenu

Returns a reference to the main window “Edit” menu.

Return type

QMenu

editableLayers(self, modified: bool = False) → List[QgsMapLayer]

Returns vector layers in edit mode

Parameters

modified (bool = False) – whether to return only layers that have been modified

Return type

List[QgsMapLayer]

Returns

list of layers in legend order, or empty list *

fileToolBar(self) → QToolBar

Returns a reference to the main window “File” toolbar.

Return type

QToolBar

firstRightStandardMenu(self) → QMenu

Returns a reference to the right most standard menu, which is usually the last menu item before the “Help” menu.

This can be used to insert additional top-level menus into their correct position BEFORE the help menu.

Return type

QMenu

getFeatureForm(self, l: QgsVectorLayer, f: QgsFeature) → QgsAttributeDialog

Returns a feature form for a given feature.

Parameters
  • l (QgsVectorLayer) – The layer for which the dialog will be created

  • f (QgsFeature) – The feature for which the dialog will be created

Return type

QgsAttributeDialog

Returns

A feature form

helpMenu(self) → QMenu

Returns a reference to the main window “Help” menu.

Return type

QMenu

helpToolBar(self) → QToolBar

Returns a reference to the main window “Help” toolbar.

Return type

QToolBar

iconSize(self, dockedToolbar: bool = False) → QSize

Returns the toolbar icon size. If dockedToolbar is true, the icon size for toolbars contained within docks is returned.

Parameters

dockedToolbar (bool = False) –

Return type

QSize

initializationCompleted

This signal is emitted when the initialization is complete. [signal]

insertAddLayerAction(self, action: QAction)

Add “add layer” action to layer menu

Parameters

action (QAction) –

invalidateLocatorResults(self)

Invalidate results from the locator filter.

This might be useful if the configuration of the filter changed without going through main application settings.

New in version 3.2.

isSignalConnected()
layerMenu(self) → QMenu

Returns a reference to the main window “Layer” menu.

Return type

QMenu

layerSavedAs

This signal is emitted when a layer has been saved using save as.

New in version 2.7: [signal]

layerToolBar(self) → QToolBar

Returns a reference to the main window “Layer” toolbar.

Return type

QToolBar

layerTreeCanvasBridge(self) → QgsLayerTreeMapCanvasBridge

Returns a pointer to the layer tree canvas bridge

New in version 2.12.

Return type

QgsLayerTreeMapCanvasBridge

layerTreeView(self) → QgsLayerTreeView
Return type

QgsLayerTreeView

layoutDesignerClosed

This signal is emitted after a layout designer window is closed.

New in version 3.0: [signal]

layoutDesignerOpened

This signal is emitted when a new layout designer has been opened.

New in version 3.0: [signal]

layoutDesignerWillBeClosed

This signal is emitted before a layout designer is going to be closed and deleted.

New in version 3.0: [signal]

mainWindow(self) → QWidget

Returns a pointer to the main window (instance of QgisApp in case of QGIS)

Return type

QWidget

mapCanvas(self) → QgsMapCanvas

Returns a pointer to the map canvas

Return type

QgsMapCanvas

mapCanvases(self) → object

Returns a list of all map canvases open in the app.

New in version 3.0.

Return type

object

mapNavToolToolBar(self) → QToolBar

Returns a reference to the main window “Map Navigation” toolbar.

Return type

QToolBar

messageBar(self) → QgsMessageBar

Returns the message bar of the main app

Return type

QgsMessageBar

messageTimeout(self) → int

Returns the timeout for timed messages: default of 5 seconds

Return type

int

newLayerMenu(self) → QMenu

Returns a reference to the main window “Create New Layer” menu.

Return type

QMenu

newProject(self, promptToSaveFlag: bool = False)

Starts a new blank project

Parameters

promptToSaveFlag (bool = False) –

newProjectCreated

Emitted when starting an entirely new project.

Note

This is similar to projectRead(); plugins might want to be notified that they’re in a new project. Yes, projectRead() could have been overloaded to be used in the case of new projects instead. However, it’s probably more semantically correct to have an entirely separate signal for when this happens. [signal]

openFeatureForm(self, l: QgsVectorLayer, f: QgsFeature, updateFeatureOnly: bool = False, showModal: bool = True) → bool

Opens a new feature form. Returns true if dialog was accepted (if shown modal, true otherwise).

Parameters
  • l (QgsVectorLayer) – vector layer

  • f (QgsFeature) – feature to show/modify

  • updateFeatureOnly (bool = False) – only update the feature update (don’t change any attributes of the layer) [UNUSED]

  • showModal (bool = True) – if true, will wait for the dialog to be executed (only shown otherwise)

Return type

bool

openLayoutDesigner(self, layout: QgsMasterLayoutInterface) → QgsLayoutDesignerInterface

Opens a new layout designer dialog for the specified layout, or brings an already open designer window to the foreground if one is already created for the layout.

New in version 3.0.

Parameters

layout (QgsMasterLayoutInterface) –

Return type

QgsLayoutDesignerInterface

openLayoutDesigners(self) → object

Returns all currently open layout designers.

New in version 3.0.

Return type

object

openMessageLog(self)

Opens the message log dock widget.

openURL(self, url: str, useQgisDocDirectory: bool = True)

Open a url in the users browser. By default the QGIS doc directory is used as the base for the URL. To open a URL that is not relative to the installed QGIS documentation, set useQgisDocDirectory to false.

Parameters
  • url (str) – URL to open

  • useQgisDocDirectory (bool = True) – If true, the URL will be formed by concatenating url to the QGIS documentation directory path (prefix/share/doc)

Deprecated since version Use: QDesktopServices instead

pasteFromClipboard(self, QgsMapLayer)

Paste features from clipboard to the layer

New in version 3.0.

pluginManagerInterface(self) → QgsPluginManagerInterface
Return type

QgsPluginManagerInterface

pluginMenu(self) → QMenu

Returns a reference to the main window “Plugin” menu.

Return type

QMenu

pluginToolBar(self) → QToolBar

Returns a reference to the main window “Plugin” toolbar.

Return type

QToolBar

preloadForm(self, uifile: str)

This method is only needed when using a UI form with a custom widget plugin and calling openFeatureForm or getFeatureForm from Python (PyQt) and you haven’t used the info tool first. Python will crash bringing QGIS with it if the custom form is not loaded from a C++ method call.

This method uses a QTimer to call QUiLoader in order to load the form via C++. You only need to call this once. After that you can call openFeatureForm/getFeatureForm like usual.

More information here: http://qt-project.org/forums/viewthread/27098

Parameters

uifile (str) –

projectMenu(self) → QMenu

Returns a reference to the main window “Project” menu.

Return type

QMenu

projectRead

Emitted when a project file is successfully read.

Note

This is useful for plugins that store properties with project files. A plugin can connect to this signal. When it is emitted, the plugin knows to then check the project properties for any relevant state. [signal]

rasterMenu(self) → QMenu

Returns a reference to the main window “Raster” menu.

Return type

QMenu

rasterToolBar(self) → QToolBar

Returns a reference to the main window “Raster” toolbar.

Return type

QToolBar

receivers()
registerCustomDropHandler(self, handler: QgsCustomDropHandler)

Register a new custom drop handler.

Note

Ownership of the factory is not transferred, and the factory must be unregistered when plugin is unloaded.

New in version 3.0.

Parameters

handler (QgsCustomDropHandler) –

registerCustomLayoutDropHandler(self, handler: QgsLayoutCustomDropHandler)

Register a new custom drop handler for layout windows.

Note

Ownership of the factory is not transferred, and the factory must be unregistered when plugin is unloaded.

New in version 3.0.

Parameters

handler (QgsLayoutCustomDropHandler) –

registerLocatorFilter(self, filter: QgsLocatorFilter)

Registers a locator filter for the app’s locator bar. Ownership of the filter is transferred to the locator.

Warning

Plugins which register filters to the locator bar must take care to correctly call deregisterLocatorFilter() and deregister their filters upon plugin unload to avoid crashes.

New in version 3.0.

Parameters

filter (QgsLocatorFilter) –

registerMainWindowAction(self, action: QAction, defaultShortcut: str) → bool

Register action to the shortcuts manager so its shortcut can be changed in GUI

Parameters
  • action (QAction) –

  • defaultShortcut (str) –

Return type

bool

registerMapLayerConfigWidgetFactory(self, factory: QgsMapLayerConfigWidgetFactory)

Register a new tab in the vector layer properties dialog.

Note

Ownership of the factory is not transferred, and the factory must be unregistered when plugin is unloaded.

New in version 2.16.

Parameters

factory (QgsMapLayerConfigWidgetFactory) –

registerOptionsWidgetFactory(self, factory: QgsOptionsWidgetFactory)

Register a new tab in the options dialog.

Note

Ownership of the factory is not transferred, and the factory must be unregistered when plugin is unloaded.

New in version 3.0.

Parameters

factory (QgsOptionsWidgetFactory) –

reloadConnections(self)

Triggered when connections have changed. This calls reloadConnections in the main application and triggers a signal that is forwarded to the GUI elements that needs to be updated (i.e. the source select dialogs and the browser widgets)

New in version 3.0.

removeAddLayerAction(self, action: QAction)

Remove “add layer” action from layer menu

Parameters

action (QAction) –

removeCustomActionForLayerType(self, action: QAction) → bool

Remove action for layers in the layer tree previously added with addCustomActionForLayerType()

Parameters

action (QAction) –

Return type

bool

removeDatabaseToolBarIcon(self, qAction: QAction)

Remove an action (icon) from the Database toolbar

Parameters

qAction (QAction) –

removeDockWidget(self, dockwidget: QDockWidget)

Removes the specified dock widget from main window (without deleting it).

See also

addDockWidget()

Parameters

dockwidget (QDockWidget) –

removePluginDatabaseMenu(self, name: str, action: QAction)

Remove action from the Database menu

Parameters
  • name (str) –

  • action (QAction) –

removePluginMenu(self, name: str, action: QAction)

Remove action from the plugins menu

Parameters
  • name (str) –

  • action (QAction) –

removePluginRasterMenu(self, name: str, action: QAction)

Remove action from the Raster menu

Parameters
  • name (str) –

  • action (QAction) –

removePluginVectorMenu(self, name: str, action: QAction)

Remove action from the Vector menu

Parameters
  • name (str) –

  • action (QAction) –

removePluginWebMenu(self, name: str, action: QAction)

Remove action from the Web menu

Parameters
  • name (str) –

  • action (QAction) –

removeRasterToolBarIcon(self, qAction: QAction)

Remove an action (icon) from the Raster toolbar

Parameters

qAction (QAction) –

removeToolBarIcon(self, qAction: QAction)

Remove an action (icon) from the plugin toolbar

Parameters

qAction (QAction) –

removeVectorToolBarIcon(self, qAction: QAction)

Remove an action (icon) from the Vector toolbar

Parameters

qAction (QAction) –

removeWebToolBarIcon(self, qAction: QAction)

Remove an action (icon) from the Web toolbar

Parameters

qAction (QAction) –

removeWindow(self, action: QAction)

Remove window from Window menu. Calling this is necessary only for windows which are hidden rather than deleted when closed. *

Parameters

action (QAction) –

saveStyleSheetOptions(self, opts: Dict[str, Any])

Save changed default option keys/values to user settings

Parameters

opts (Dict[str) –

sender()
senderSignalIndex()
setActiveLayer(self, QgsMapLayer) → bool

Set the active layer (layer gets selected in the legend) returns true if the layer exists, false otherwise

Return type

bool

settingsMenu(self) → QMenu

Returns a reference to the main window “Settings” menu.

Return type

QMenu

shapeDigitizeToolBar(self) → QToolBar

Returns a reference to the main window “Shape Digitizing” toolbar.

New in version 3.0.

Return type

QToolBar

showAttributeTable(self, l: QgsVectorLayer, filterExpression: str = '') → QDialog

Open attribute table dialog

Parameters
Return type

QDialog

showLayerProperties(self, l: QgsMapLayer)

Open layer properties dialog

Parameters

l (QgsMapLayer) –

showLayoutManager(self)

Opens the layout manager dialog.

New in version 3.0.

showOptionsDialog(self, parent: QWidget = None, currentPage: str = '')

Opens the options dialog. The currentPage argument can be used to force the dialog to open at a specific page.

New in version 3.0.

Parameters
  • parent (QWidget = None) –

  • currentPage (str = '') –

statusBarIface(self) → QgsStatusBar

Returns a pointer to the app’s status bar interface. This should be used for interacting and adding widgets and messages to the app’s status bar (do not use the native Qt statusBar() method).

New in version 3.0.

Return type

QgsStatusBar

takeAppScreenShots(self, saveDirectory: str, categories: int = 0)

Take screenshots for user documentation @param saveDirectory path where the screenshots will be saved @param categories an int as a flag value of QgsAppScreenShots.Categories

New in version 3.4.

Parameters
  • saveDirectory (str) –

  • categories (int = 0) –

timerEvent()
unregisterCustomDropHandler(self, handler: QgsCustomDropHandler)

Unregister a previously registered custom drop handler.

New in version 3.0.

Parameters

handler (QgsCustomDropHandler) –

unregisterCustomLayoutDropHandler(self, handler: QgsLayoutCustomDropHandler)

Unregister a previously registered custom drop handler for layout windows.

New in version 3.0.

Parameters

handler (QgsLayoutCustomDropHandler) –

unregisterMainWindowAction(self, action: QAction) → bool

Unregister a previously registered action. (e.g. when plugin is going to be unloaded)

Parameters

action (QAction) –

Return type

bool

unregisterMapLayerConfigWidgetFactory(self, factory: QgsMapLayerConfigWidgetFactory)

Unregister a previously registered tab in the vector layer properties dialog.

New in version 2.16.

Parameters

factory (QgsMapLayerConfigWidgetFactory) –

unregisterOptionsWidgetFactory(self, factory: QgsOptionsWidgetFactory)

Unregister a previously registered tab in the options dialog.

New in version 3.0.

Parameters

factory (QgsOptionsWidgetFactory) –

vectorLayerTools(self) → QgsVectorLayerTools

Access the vector layer tools instance. With the help of this you can access methods like addFeature, startEditing or stopEditing while giving the user the appropriate dialogs.

Return type

QgsVectorLayerTools

Returns

An instance of the vector layer tools

vectorMenu(self) → QMenu

Returns a reference to the main window “Vector” menu.

Return type

QMenu

vectorToolBar(self) → QToolBar

Returns a reference to the main window “Vector” toolbar.

Return type

QToolBar

viewMenu(self) → QMenu

Returns a reference to the main window “View” menu.

Return type

QMenu

webMenu(self) → QMenu

Returns a reference to the main window “Web” menu.

Return type

QMenu

webToolBar(self) → QToolBar

Returns a reference to the main window “Web” toolbar.

Return type

QToolBar

windowMenu(self) → QMenu

Returns a reference to the main window “Window” menu.

Return type

QMenu

zoomFull(self)

Zooms to the full extent of all map layers.

zoomToActiveLayer(self)

Zooms to extent of the active layer.

zoomToNext(self)

Zooms to the next view extent.

zoomToPrevious(self)

Zooms to the previous view extent.