PDA

View Full Version : excluding an area from painting using clip path



berliner
11th May 2009, 22:02
Hi,

I'm in the process of porting an MFC/GDI+ application to QT. So far it was fairly smooth, but now I have a problem with clipping. I need to be able to exclude an area from painting.

In GDI this is done with the flag CombineModeExclude like this:

....paint dark rectagle....

...add hexagon points to "pointList"...

GraphicsPath path(FillModeAlternate);
path.AddPolygon(pointList, count);
graphics.SetClip(&path, CombineModeExclude);

...paint bright rectangle...


That creates something like this:
http://up.picr.de/2253110.png

The hexagon is the path that is excluded from clipping. Qt doens't seem to provide something similar among it's flags in enum Qt::ClipOperation. I can include areas, but not exclude.

Does anyone have a workaround or an idea how to achieve this in Qt?

e8johan
12th May 2009, 15:02
I'd say that a QPainterPath, with the rectangle and the polygon, set to odd/even filling mode, aught to do it.

berliner
15th May 2009, 00:27
well, correct, my example can be obtained with odd/even filling, but if I move the hexagon a little bit so that it is not completely enclosed by the rectangle, the odd/even rule will probably create something like this:
http://up.picr.de/2266772.png

But I want to have this:
http://up.picr.de/2266725.png

I'm a little bit puzzled, because that kind of clipping mode is available in GDI as well as X11. I don't know if Qt just forwards to the native OS functions or has it's own implementation of clipping algorithms.

However, currently areas or shapes can only be included for updates, but it's very useful to also be able to exclude an area from painting. I was already thinking if I could somehow use a mask bitmap. I would paint the hexagon into a monochrome mask, then draw the bright rectangle into a temporary QImage, then blit that one into the the visible image using a logical operation (src AND NOT mask into dest).

GDIs MaskBlt has the dwRop parameter to define a ternary raster operation of source, dest and mask.

The question is then, how to involve a mask in painting in Qt? QPainter::CompositionMode only defines operations between src and dest, but not involving a mask.

lni
15th May 2009, 00:38
Have you checked QPainter's clipping methods?

berliner
15th May 2009, 02:30
Yes, but Qt::ClipOperation only knows NoClip, ReplaceClip, IntersectClip, UniteClip. I would need ExcludeClip.