Results 1 to 5 of 5

Thread: excluding an area from painting using clip path

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2009
    Location
    Berlin
    Posts
    14
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default excluding an area from painting using clip path

    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:


    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?
    Last edited by berliner; 11th May 2009 at 22:12.

  2. #2
    Join Date
    Jan 2006
    Location
    Alingsås, Sweden
    Posts
    437
    Thanks
    3
    Thanked 39 Times in 39 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: excluding an area from painting using clip path

    I'd say that a QPainterPath, with the rectangle and the polygon, set to odd/even filling mode, aught to do it.

  3. #3
    Join Date
    May 2009
    Location
    Berlin
    Posts
    14
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: excluding an area from painting using clip path

    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:


    But I want to have this:


    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.
    Last edited by berliner; 15th May 2009 at 02:29.

  4. #4
    Join Date
    Dec 2006
    Posts
    426
    Thanks
    8
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: excluding an area from painting using clip path

    Have you checked QPainter's clipping methods?

  5. #5
    Join Date
    May 2009
    Location
    Berlin
    Posts
    14
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: excluding an area from painting using clip path

    Yes, but Qt::ClipOperation only knows NoClip, ReplaceClip, IntersectClip, UniteClip. I would need ExcludeClip.

Similar Threads

  1. Compute the area under a curve
    By giusepped in forum Qwt
    Replies: 0
    Last Post: 26th December 2008, 06:56
  2. leaveEvent on transparent area issue
    By nooky59 in forum Qt Programming
    Replies: 10
    Last Post: 8th January 2008, 13:22
  3. Replies: 3
    Last Post: 13th November 2007, 10:30
  4. Initialise toolbar in a different area
    By georgie in forum Qt Programming
    Replies: 4
    Last Post: 4th May 2006, 03:49
  5. QRubberBand painting in the scroll area widget
    By SkripT in forum Qt Programming
    Replies: 7
    Last Post: 17th January 2006, 16:48

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.