[Qt-interest] Inverting a QPainterPath
Josiah Bryan
jbryan at productiveconcepts.com
Wed Oct 7 17:53:14 CEST 2009
Josiah Bryan wrote:
> David Boddie wrote:
>> Josiah Bryan wrote:
>>
>>> In reading the QPainterPath documentation at
>>> (http://doc.trolltech.com/4.5/qpainterpath.html), I dont see a way to
>>> "turn inside out" or "invert" the QPainter path. For example, in GIMP,
>>> you can create a selection (or path from text) then "invert" it so
>>> everything but the original path is selected. Is that dooable with a
>>> QPainterPath?
>> Create another painter path, add a rectangle to it, and subtract the first
>> path from it. Then draw that.
>>
>> http://doc.trolltech.com/4.5/qpainterpath.html#subtracted
>
> How in the world did I miss ::subtracted ?? Crikey! That's exactly what
> I was looking for. Sorry everyone!
>
Worked perfectly!
Sample code:
QPainterPath clipPath;
clipPath.addRect(QRectF(0,0,contentsRect().width(),contentsRect().height()));
QTextPath textPath;
textPath.addText(...);
QPainterPath textClip = clipPath.subtracted(textPath);
painter->setClipPath(textClip);
Beautiful! Thanks Jason and David.
Cheers!
-josiah
More information about the Qt-interest-old
mailing list