Graphics Reference
In-Depth Information
symbol layers correct, or you might find a symbol layer completely obscured by another
layer.
While the symbols we have been working with so far have had only one layer, there are
some clever tricks you can perform with multilayer symbols. We will look at multilayer
symbols in the section Combining symbol layers .
When you create a symbol, it will automatically be initialized with a default symbol layer.
For example, a line symbol (an instance of QgsLineSymbolV2 ) will be created with a
single layer of type QgsSimpleLineSymbolLayerV2 . This layer is used to draw the
line feature onto the map.
To work with symbol layers, you need to remove this default layer and replace it with
your own symbol layer or layers. For example:
symbol = QgsSymbolV2.defaultSymbol(layer.geometryType())
symbol.deleteSymbolLayer(0) # Remove default symbol layer.
symbol_layer_1 = QgsSimpleFillSymbolLayerV2()
symbol_layer_1.setFillColor(QColor("yellow"))
symbol_layer_2 = QgsLinePatternFillSymbolLayer()
symbol_layer_2.setLineAngle(30)
symbol_layer_2.setDistance(2.0)
symbol_layer_2.setLineWidth(0.5)
symbol_layer_2.setColor(QColor("green"))
symbol.appendSymbolLayer(symbol_layer_1)
symbol.appendSymbolLayer(symbol_layer_2)
The following methods can be used to manipulate the layers within a symbol:
symbol.symbolLayerCount() : This returns the number of symbol layers
within this symbol.
symbol.symbolLayer(index) : This returns the given symbol layer within
the symbol. Note that the first symbol layer has an index of zero.
symbol.changeSymbolLayer(index, symbol_layer) : This replaces
a given symbol layer within the symbol.
symbol.appendSymbolLayer(symbol_layer) : This appends a new
symbol layer to the symbol.
Search WWH ::




Custom Search