PDA

View Full Version : Having trouble understanding brush



feraudyh
30th July 2010, 16:38
Hi,
I want to draw for a GIS application. In GIS what we call Polygons have holes in them,
so I store a GIS polygon as an array of QPolygonF.
The first element of the array is the outer polygon and the following elements are the holes.
Now I'd like those holes to be transparent, in other words filled with a different brush to the outer polygon.
The trouble is that I havent been able to manage to get my bush to change dynamically as I am doing here:

void Polygon::draw(LPainter &qp)
{//LPainter is derived from QPainter, has a couple of extra members

qp.drawPolygon(m_QPolygonF_Array[0]);
const QBrush save_brush = qp.brush();
// then draw the other inner rings, but with another brush...!!!
qp.setBrush(*LayerPainter::transparent_brush);// use a separate global brush
for(int i=1;i <m_QPolygonF_Array.count();i++)
qp.drawPolygon(m_QPolygonF_Array[i]);
qp.setBrush(save_brush);
}


This code does not draw the holes in a different way to the outer ring.
Is this due to an optimisation, which means it would be be better to save all my inner rings for a separate pass of drawing?

tbscope
30th July 2010, 17:19
To me this sounds obvious. For example:
If I have a big yellow circle and then draw a small circle on top of it with a transparent background, you will see what's underneath it, and that's the big yellow circle.

I think you want to draw all the polygons first and then color between the polygons or subtract the polygons

feraudyh
30th July 2010, 17:59
Hi,
I found a solution to my problem by drawing all the QPolygonF's of my GIS layer first and then I drew all the holes with an opaque white brush.

However when I tried to do it Polygon by Polygon: drawing the outer QPolygonF first and then changing the brush to an opaque white brush
and drawing the holes and then trying to revert the brush
I ended up having a white brush in my entire set of layers!
There just seemed to be no way of reverting the brush to the original non-white value.

feraudyh
30th July 2010, 18:08
A very similar problem occurred when I wanted to temporarily change the pen, and then revert to its original settings. It just didnt seem to work at the
microscopic level, only at a macroscopic level.

tbscope
30th July 2010, 18:18
painter.save() --> saves the state
...
set some pens and brushes, do some painting
...
painter.restore() --> restores the state