[Qgis-developer] Adding custom fill styles?

Marco Hugentobler marco.hugentobler at karto.baug.ethz.ch
Wed May 16 02:55:09 EDT 2007

Hi Steven,

Custom fill styles would be a nice enhancement for QGIS!

> I'm
> wondering if it would be possible to create custom styles using
> QBrush::setTexture().

Yes, that's the way to go. 
It is better to use QBrush::setTextureImage() function instead of the pixmap 
one. In qgis core lib, we avoid using QPixmap. QPixmap needs a running 
X-Server and is a problem for server applications using qgis lib.

> How difficult would this be to implement? 
I think that most work to be done will be gui related.

> and someone can help get me pointed in the right direction.

The symbology (QPen, QBrush and possibly image for point symbols) is stored in 
QGIS inside the class QgsSymbol. 

The renderer classes (e.g. QgsSingleSymbolRenderer, 
QgsGraduatedSymbolRenderer, etc.) contain one or more QgsSymbols, together 
with the information which symbol to apply for which attribute value. If 
QgsVectorLayer draws a feature, it passes the feature to a subclass of 
QgsRenderer first and the renderer class sets the pen and brush (and possibly 
the image) according to the attribute value of the feature. The vector layer 
then draws the feature without having anything to know about the feature 

Important is the class QgsSingleSymbolDialog. This class is used to enter the 
settings for a QgsSymbol. It is used also by QgsGraduatedSymbolDialog and 
QgsUniqueValueDialog. It creates the settings for a QgsSymbol according to 
user input. And I think QgsSingleSymbolDialog::apply(QgsSymbol*)  is the 
place, where the QImage for a custom fill style should be passed to 
QgsSymbol. QgsSymbol then calls setTextureImage() for its brush. 
QgsSingleSymbol could provide also the gui for a user to choose an image (or 
a button that gives access to that gui).

>Is this what "
> qgsfillstylewidget.cpp" was meant for?

qgsfillstylewidget.cpp is legacy code. There was a discussion once about 
having different gui for vector symbolisation, and I think this widget was 
meant to be part of it.

If you have further questions, don't hesitate to ask. Also, it would be good 
if you communicate from time to time your progresses, ideas, etc. on the 
devel mailing list.

I would very much appreciate your contribution. For QGIS, it is always a 
problem that we do not have enough developers regarding the amount of code in 
the project.

All the best,

Dr. Marco Hugentobler
Institute of Cartography
ETH Zurich
marco.hugentobler at karto.baug.ethz.ch

More information about the Qgis-developer mailing list