Results 1 to 5 of 5

Thread: Draw polygon with holes

  1. #1

    Default Draw polygon with holes

    Hello,

    I need to draw polygon with holes, the holes are also polygons, how do to build a graphics item like this in qt4?
    I am thinking to construct it with QPainterPath, but I am not sure how to do it.

    Any ideas?

  2. #2
    Join Date
    Mar 2008
    Posts
    141
    Thanks
    10
    Thanked 9 Times in 9 Posts

    Default Re: Draw polygon with holes

    Hi,

    not sure if this is the best solution, but I am doing something like this:

    Qt Code:
    1. //add outer points
    2. path.addPolygon(p);
    3. //add inner points
    4. inner.addPolygon(p);
    5. path = path.subtracted(inner);
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2006
    Location
    La Spezia,Italy
    Posts
    77
    Thanks
    9
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Draw polygon with holes

    Hi, It seemed to me that this version is faster:

    Qt Code:
    1. QRegion clip(path);
    2.  
    3. clip-=QRegion(sub);
    4.  
    5. paint.setClipRegion(clip);
    6.  
    7. paint.fillPath(path,brush);
    To copy to clipboard, switch view to plain text mode 

  4. #4

    Smile Re: Draw polygon with holes

    Thanks for these suggestions.
    I will try them tomorrow and get back to here. I am just too drunk now.
    Need to get some sleep

  5. #5

    Default Re: Draw polygon with holes

    Hi,
    I think I will use the first method right now. If I need to write a customized graphics item, the second one may be a good choice.

    BTW: is there any particular reason that the second method is faster than first one?

    Thanks for help!

Similar Threads

  1. Use delegate to draw different type of items
    By nifei in forum Qt Programming
    Replies: 1
    Last Post: 19th January 2009, 13:16
  2. Optimizing polygon clipping in QGraphicsScene drawing
    By maverick_pol in forum Qt Programming
    Replies: 1
    Last Post: 28th September 2008, 20:41
  3. Rotating the polygon
    By navi1084 in forum Qt Programming
    Replies: 1
    Last Post: 4th September 2008, 00:41
  4. Creating clipped polygon
    By maverick_pol in forum Qt Programming
    Replies: 10
    Last Post: 27th August 2008, 23:15
  5. Using QGLWidget paint engine to draw regular widgtes?
    By high_flyer in forum Qt Programming
    Replies: 11
    Last Post: 9th October 2006, 12:06

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.