[Qt-interest] Inverting a QPainterPath

Josiah Bryan jbryan at productiveconcepts.com
Wed Oct 7 17:35:50 CEST 2009


Jason H wrote:
> Also see "Composing a QPainterPath" in the docs, which might work, provided you realize you can fill transparent

Yeah, I poured over that section, looking for something like "subtract 
this path from another." So, something like fill a QPixmap with 
non-transparent (black), paint the path with transparency on a QPixmap, 
which effectively subtracts it from the non-transparent part. That makes 
perfect sense.

But how to I then use that QPixmap as the "clipping path" (or whatever) 
for subsequent arbitrary QPainter operations? (Say, drawing another 
QPainter path in a custom QGraphicsItem)? (That is, where I can't just 
set a QPixmap as the alpha channel of an output pixmap and be done with 
it - I'm rendering using the QPainter given by QGraphicsItem.)

Thanks!
-josiah


> 
> ----- Original Message ----
> From: Josiah Bryan <jbryan at productiveconcepts.com>
> To: Qt Interest <qt-interest at trolltech.com>
> Sent: Wed, October 7, 2009 10:56:22 AM
> Subject: [Qt-interest] Inverting a QPainterPath
> 
> Is there a way to "invert" a QPainterPath?
> 
> Here's what I want to do:
> 
> -Create QPainterPath
> -Add Text to it (say, "Foobar")
> -"Invert" the path so I can use it as a clipping path for a QPainter
> -Fill QPainter with some Image
> -Now only the pixels of the image OUTSIDE the letters "Foobar" are 
> painted. (e.g. the background already existing "shows thru" the letters 
> "foobar".)
> 
> 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?
> 
> Thanks for your time!
> 
> -josiah
> 

-- 

-=-=-=-=-=-=-=-=-=-=-=-=-
Josiah Bryan
Productive Concepts, Inc.
jbryan at pciint.com
(765) 964-6009, ext. 224




More information about the Qt-interest-old mailing list