Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 3

Qt-interest Archive, March 2002
QCanvasPolygon: no pen?!??!?!


Message 1 in thread

Please, someone tell me I have read it incorrectly, and it is somehow possible 
to draw the outline of a polygon without having to reimplement QCanvasPolygon.

Please. I think I must be going mad.
-- 
 [ signature omitted ] 

Message 2 in thread

I had some trouble trying to subclass QCanvasPolygon (and
QCanvasPolygonalItem) to do polylines. I tried overriding both the draw()
(think that was what it was called ) method and the areaPoints() but it
messed up. Maybe someone can correct me but I think you might have to go
deeper into the code to do this. Bit of a shame really...

I have however developed my own classes for dealing with this problem - I
have an MMDrawLIst which is a list for drawing a mixture of pixmaps, text
and lines and polylines, and an MMDrawObject. The code as it stands is
tailored for my particular use - map drawing - but could be changed.

It's available as part of my Mapmaker program (www.hogweed.org/mapmaker).

Nick

--
 [ signature omitted ] 

Message 3 in thread

Okay, so so far I understand the conceptual problem to be this: The clipping 
region for the polygon is set to be something based on the point array that 
defines the polygon. The problem comes when you try and draw the outline, 
which is larger than the polygon itself, due to the width of the pen.

However, I suspect this is a solved problem, and we just have to find the 
solution.

My first idea is to compute a new polygon that is scaled up by half the width 
of the pen. I think the scaling could be done by determining the center point 
of the polygon, and then translating each point away from the center point by 
the half width.

I haven't sat down and thought through it all the way, so there may be caveats 
in that method.

As to why the region needs to be computed, I think it's used to compute 
collisions.


-- 
 [ signature omitted ] 

Message 4 in thread

Came into this thread mid-way, hope this helps:

I ran into the same problem a while back and was able to overload drawShape
to draw the lines, using eithe drawPolyline() or drawLine( ).  I used the
internal protected member var "poly" from QCanvasPolygon so I didn't have
to overload move() and moveBy(). I didn't have to worry about areaPoints()
too much in my application, so this might not help that much.  Looks
something like this:

class CSelectionPolygon : public QCanvasPolygon
{
...
};

...

void CSelectionPolygon::drawShape( QPainter& p )
{
    if ( poly.size() > 1 )
    {
        p.save();

        p.setPen( red );
#define DRAW_LINES
#ifdef DRAW_LINES
        for ( int i = 0; i< poly.size() - 1; i++ )
        {
            p.drawLine( poly.point( i ), poly.point( i + 1 ) );
        }
#else
        p.drawPolyline( poly, 0, poly.size() );
#endif
#define DRAW_DEBUG_POLYGON
#ifdef DRAW_DEBUG_POLYGON
        p.save();
        p.setBrush( blue );
        p.drawPolygon( poly );
        p.restore();
#endif

        p.restore();
    }
}




                                                                                                     
                    Hacksaw                                                                          
                    <hacksaw@hacksaw.org>      To:     Nick Whitelegg <bssnrw@bath.ac.uk>            
                    Sent by:                   cc:     qt-interest@trolltech.com                     
                    owner-qt-interest@tro      Subject:     Re: QCanvasPolygon: no pen?!??!?!        
                    lltech.com                                                                       
                                                                                                     
                                                                                                     
                                                                                                     
                    03/10/02 10:46 AM                                                                
                    Please respond to                                                                
                    hacksaw                                                                          
                                                                                                     
                                                                                                     



Okay, so so far I understand the conceptual problem to be this: The
clipping
region for the polygon is set to be something based on the point array that

defines the polygon. The problem comes when you try and draw the outline,
which is larger than the polygon itself, due to the width of the pen.

However, I suspect this is a solved problem, and we just have to find the
solution.

My first idea is to compute a new polygon that is scaled up by half the
width
of the pen. I think the scaling could be done by determining the center
point
of the polygon, and then translating each point away from the center point
by
the half width.

I haven't sat down and thought through it all the way, so there may be
caveats
in that method.

As to why the region needs to be computed, I think it's used to compute
collisions.


--
 [ signature omitted ]