- Announcing the release of QGIS 1.5 'Tethys'
- Quantum GIS on steroids
- Annotation tools
- Announcing the release of QGIS 1.4.0 'Enceladus'
- Carson Farmer's report back on the Vienna Hackfest
- Vienna Hackfest 2009 Report Back
- Introducing the QGIS Hackfest (Vienna 2009) crew
- Announcing the release of QGIS 1.3.0 'Mimas'
- Announcing the releases of QGIS 1.0.2 (stable) and QGIS 1.1.0 'Pan' (unstable).
- Summer of Code project: Label placement
Annotation tools
Since a few days, the annotation tools are contained in the developer version of QGIS. In this blogpost, I'd like to explain what those tools are and how to use them.
Text annotations
The text annotation item provides the possibility to place formated text in a balloon on the QGIS map canvas. Use the text annotation tool and click into the map canvas.
Now you are going to see an item like this.
Double click on the item opens a dialog with various options. There is the text editor to enter the formated text and other item settings. E.g. there is the choice of having the item placed on a map position (displayed by a marker symbol) or to have the item on a screen position (not related to the map). The item can be moved by map position (drag the map marker) or by moving only the balloon.
Form annotations
The form item is useful to display attributes of a vector layer in a customised qt designer form. It is similar to Juergens designer forms for the identify tool, but displayed in an annotation item. Here is a little example on how to use it. Let's say we have a layer with municipalities with the attributes 'name' and 'plz' (postal code). Now we create a .ui file with qt designer with two line edits to display name and postal code. If we give the line edits the names of the attributes, QGIS knows that if needs to fill in the attributes into those GUI elements.
Now we load the layer in QGIS and set the designer form field (vector properties->general->Edit UI). Or we may set the file in the item property dialog after placing a form item and double clicking on it.
Both the form and text annotation items also appear in the map composer module.
Python bindings.
Annotation items can also be used from python plugins or the python console. Here are two examples:
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.core import *
from qgis.gui import *
textItem = QgsTextAnnotationItem( qgis.utils.iface.mapCanvas() )
textItem.setMapPosition(QgsPoint(739433, 224091))
textItem.setFrameSize(QSizeF(200,100))
textItem.setDocument(QTextDocument("This is my text item")))
textItem.update()
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.core import *
from qgis.gui import *
formItem = QgsFormAnnotationItem( qgis.utils.iface.mapCanvas(), qgis.utils.iface.activeLayer() )
formItem.setMapPosition(QgsPoint(696718, 241215))
formItem.setDesignerForm("/path/to/my/designerfile.ui");
formItem.update()
Acknowledgment
This development has been funded by the Canton of Solothurn (Switzerland). Thanks!
- mhugent's blog
- Login or register to post comments
- 3600 reads



Recent comments
51 weeks 1 day ago
1 year 5 weeks ago
1 year 6 weeks ago
1 year 6 weeks ago
1 year 8 weeks ago
1 year 14 weeks ago
1 year 14 weeks ago
1 year 15 weeks ago
1 year 15 weeks ago
1 year 15 weeks ago