Graphics Reference
In-Depth Information
The qgis.gui package
The qgis.gui package defines a number of user-interface widgets that you can include
in your programs. Let's start by looking at the most important qgis.gui classes, and fol-
low this up with a brief look at some of the other classes that you might find useful.
The QgisInterface class
QgisInterface represents the QGIS system's user interface. It allows programmatic ac-
cess to the map canvas, the menu bar, and other parts of the QGIS application. When run-
ning Python code within a script or a plugin, or directly from the QGIS Python console, a
reference to QgisInterface is typically available through the iface global variable.
Note
The QgisInterface object is only available when running the QGIS application itself.
If you are running an external application and import the PyQGIS library into your applica-
tion, QgisInterface won't be available.
Some of the more important things you can do with the QgisInterface object are:
• Get a reference to the list of layers within the current QGIS project via the le-
gendInterface() method.
• Get a reference to the map canvas displayed within the main application window,
using the mapCanvas() method.
• Retrieve the currently active layer within the project, using the activeLayer()
method, and set the currently active layer by using the setActiveLayer()
method.
• Get a reference to the application's main window by calling the mainWindow()
method. This can be useful if you want to create additional Qt windows or dialogs
that use the main window as their parent.
• Get a reference to the QGIS system's message bar by calling the messageBar()
method. This allows you to display messages to the user directly within the QGIS
main window.
The QgsMapCanvas class
The map canvas is responsible for drawing the various map layers into a window. The
QgsMapCanvas class represents a map canvas. This class includes:
Search WWH ::




Custom Search