Graphics Reference
In-Depth Information
rings or "holes" within the polygon. As always, context is the rendering context to use
when drawing the geometry.
A custom symbol layer created in this way will work fine if you just want to use it within
your own external PyQGIS application. However, if you want to use a custom symbol lay-
er within a running copy of QGIS, and in particular, if you want to allow end users to
work with the symbol layer using the Layer Properties window, there are some extra
steps you will have to take, which are as follows:
• If you want the symbol to be visually highlighted when the user clicks on it, you
will need to change your symbol layer's renderXXX() method to see if the fea-
ture being drawn has been selected by the user, and if so, change the way it is
drawn. The easiest way to do this is to change the geometry's color. For example:
if context.selected():
color = context.selectionColor()
else:
color = self.color
• To allow the user to edit the symbol layer's properties, you should create a sub-
class of QgsSymbolLayerV2Widget , which defines the user interface to edit
the properties. For example, a simple widget for the purpose of editing the length
and width of a CrossSymbolLayer can be defined as follows:
class CrossSymbolLayerWidget(QgsSymbolLayerV2Widget):
def __init__(self, parent=None):
QgsSymbolLayerV2Widget.__init__(self, parent)
self.layer = None
self.lengthField = QSpinBox(self)
self.lengthField.setMinimum(1)
self.lengthField.setMaximum(100)
self.connect(self.lengthField,
SIGNAL("valueChanged(int)"),
self.lengthChanged)
self.widthField = QSpinBox(self)
self.widthField.setMinimum(1)
self.widthField.setMaximum(100)
self.connect(self.widthField,
Search WWH ::




Custom Search