Results 1 to 5 of 5

Thread: Having trouble understanding brush

  1. #1
    Join Date
    Nov 2009
    Location
    Laval, France
    Posts
    124
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Having trouble understanding brush

    Hi,
    I want to draw for a GIS application. In GIS what we call Polygons have holes in them,
    so I store a GIS polygon as an array of QPolygonF.
    The first element of the array is the outer polygon and the following elements are the holes.
    Now I'd like those holes to be transparent, in other words filled with a different brush to the outer polygon.
    The trouble is that I havent been able to manage to get my bush to change dynamically as I am doing here:
    Qt Code:
    1. void Polygon::draw(LPainter &qp)
    2. {//LPainter is derived from QPainter, has a couple of extra members
    3.  
    4. qp.drawPolygon(m_QPolygonF_Array[0]);
    5. const QBrush save_brush = qp.brush();
    6. // then draw the other inner rings, but with another brush...!!!
    7. qp.setBrush(*LayerPainter::transparent_brush);// use a separate global brush
    8. for(int i=1;i <m_QPolygonF_Array.count();i++)
    9. qp.drawPolygon(m_QPolygonF_Array[i]);
    10. qp.setBrush(save_brush);
    11. }
    To copy to clipboard, switch view to plain text mode 

    This code does not draw the holes in a different way to the outer ring.
    Is this due to an optimisation, which means it would be be better to save all my inner rings for a separate pass of drawing?
    Last edited by feraudyh; 30th July 2010 at 16:56. Reason: oops coding error

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Having trouble understanding brush

    To me this sounds obvious. For example:
    If I have a big yellow circle and then draw a small circle on top of it with a transparent background, you will see what's underneath it, and that's the big yellow circle.

    I think you want to draw all the polygons first and then color between the polygons or subtract the polygons

  3. #3
    Join Date
    Nov 2009
    Location
    Laval, France
    Posts
    124
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Having trouble understanding brush

    Hi,
    I found a solution to my problem by drawing all the QPolygonF's of my GIS layer first and then I drew all the holes with an opaque white brush.

    However when I tried to do it Polygon by Polygon: drawing the outer QPolygonF first and then changing the brush to an opaque white brush
    and drawing the holes and then trying to revert the brush
    I ended up having a white brush in my entire set of layers!
    There just seemed to be no way of reverting the brush to the original non-white value.

  4. #4
    Join Date
    Nov 2009
    Location
    Laval, France
    Posts
    124
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Having trouble understanding brush

    A very similar problem occurred when I wanted to temporarily change the pen, and then revert to its original settings. It just didnt seem to work at the
    microscopic level, only at a macroscopic level.

  5. #5
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Having trouble understanding brush

    painter.save() --> saves the state
    ...
    set some pens and brushes, do some painting
    ...
    painter.restore() --> restores the state

Similar Threads

  1. Trouble understanding QQuaternions
    By MattPhillips in forum Qt Programming
    Replies: 2
    Last Post: 21st April 2010, 02:40
  2. something like colordialog, but with brush
    By Noxxik in forum Qt Programming
    Replies: 2
    Last Post: 22nd February 2009, 20:22
  3. QwtPlot Brush and PDF output
    By giusepped in forum Qwt
    Replies: 1
    Last Post: 21st January 2009, 18:41
  4. Painter brush question
    By maverick_pol in forum Qt Programming
    Replies: 5
    Last Post: 22nd October 2008, 07:39
  5. QPalette::brush
    By tpf80 in forum Newbie
    Replies: 6
    Last Post: 17th July 2007, 23:23

Tags for this Thread

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.