Results 1 to 7 of 7

Thread: QPolygonF created from QRectF has five(?!) points

  1. #1
    Join Date
    Jul 2009
    Posts
    74
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Question QPolygonF created from QRectF has five(?!) points

    In order to use QTransform::quadToQuad, I convert two rectangles to QPolygonF.

    Qt Code:
    1. void GenericScale::paintGrid(QPainter *painter,
    2. QRectF logicalRect)
    3. {
    4. QPolygonF drawRect(logicalRect);
    5.  
    6. qDebug() << drawRect;
    7. }
    To copy to clipboard, switch view to plain text mode 

    The resulting QPolygonF has - according to watch window and qDebug output - 5 points:

    Qt Code:
    1. QPolygonF(QPointF(0, 1) QPointF(57, 1) QPointF(57, 2) QPointF(0, 2) QPointF(0, 1) )
    To copy to clipboard, switch view to plain text mode 

    Naturally, quadToQuad fails.

    Why would the constructor of QPolygonF taking a QRectF as an argument create a QPolygonF with five instead of four points?

  2. #2
    Join Date
    Oct 2009
    Location
    Mexico
    Posts
    81
    Thanks
    6
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QPolygonF created from QRectF has five(?!) points

    QPolygon consist in a QVector<QPoint>, convert a QRect to a QPolygon you need 5 point because a QRect is a closed shape, the first and last point are in the same position.

    if you only need the 4 corners of the QRect, only remove the last qpoint.

    sorry my poor english
    Last edited by ecanela; 3rd November 2010 at 19:01. Reason: updated contents

  3. The following user says thank you to ecanela for this useful post:

    Asperamanca (4th November 2010)

  4. #3
    Join Date
    Jul 2009
    Posts
    74
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QPolygonF created from QRectF has five(?!) points

    Hmmm...this doesn't quite make sense.
    If you want a closed polygon, you still would only specify 4 points to fully define the polygon. You'd just have to specify it's a closed polygon (just as OpenGL does).

    Why would I manipulate my data just to achieve something that should be a functionality of the class?

  5. #4
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QPolygonF created from QRectF has five(?!) points

    QPolygons are not implicitly closed. If you want a closed QPolygon, you need an additional endpoint that coincides with the opposite endpoint.

  6. The following user says thank you to SixDegrees for this useful post:

    Asperamanca (4th November 2010)

  7. #5
    Join Date
    Jul 2009
    Posts
    74
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QPolygonF created from QRectF has five(?!) points

    Quote Originally Posted by SixDegrees View Post
    QPolygons are not implicitly closed. If you want a closed QPolygon, you need an additional endpoint that coincides with the opposite endpoint.
    Ouch. This is ugly.

    Thanks for the replies, though!

  8. #6
    Join Date
    Feb 2007
    Location
    Italy
    Posts
    69
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QPolygonF created from QRectF has five(?!) points

    Well I had the same question, the documentation a bit obscure:

    QPolygonF::QPolygonF ( const QRectF & rectangle )
    Constructs a closed polygon from the specified rectangle.
    The polygon contains the four vertices of the rectangle in clockwise order starting and ending with the top-left vertex.
    See also isClosed().
    But looking ad isClosed:

    bool QPolygonF::isClosed () const
    Returns true if the polygon is closed; otherwise returns false.
    A polygon is said to be closed if its start point and end point are equal.
    So it says it have 4 vertex, but one is equal.
    I wonder why QPolygon and QPolygonF are different on this aspect.

  9. #7
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QPolygonF created from QRectF has five(?!) points

    In nearly all computational geometry implementations, polygons are treated the same way Qt treats them, both in number of points and closed versus open count. Qt is simply following common practice here.

Similar Threads

  1. QPolygonF preview for a custom QGraphicsItem
    By matteo.boscolo in forum Qt Programming
    Replies: 1
    Last Post: 16th July 2010, 16:04
  2. Error in QPolygonF::subtracted
    By lni in forum Qt Programming
    Replies: 1
    Last Post: 25th June 2010, 01:27
  3. Rotate a QRectF
    By whitefurrows in forum Qt Programming
    Replies: 5
    Last Post: 15th July 2009, 15:33
  4. Sorting QPolygonF
    By giusepped in forum Qt Programming
    Replies: 3
    Last Post: 7th January 2009, 08:34
  5. QRectF and drawText
    By aronsson in forum Qt Programming
    Replies: 1
    Last Post: 4th July 2006, 16:05

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.