Results 1 to 2 of 2

Thread: addPoints or addPoint

  1. #1
    Join Date
    Jan 2006
    Posts
    46
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default addPoints or addPoint

    Hi,

    I'm trying to draw a convex polygon but I don't understand how to give the
    coordinates.

    I understood that the first number is an array index (which gives a segmentation
    fault if started at 0, so it must start at 1, yes?).

    But stuff like :
    pts.setPoints(1, 240, 210, 260, 230, 300, 150, 320, 170);
    either does nothing visible or draws lines all over the place

    And when I try to add points one by one with :
    pts.setPoint(1, 240, 210);
    pts.setPoint(2, 260, 230);
    pts.setPoint(3, 300, 150);
    pts.setPoint(4, 320, 170);

    I get errors like:
    QGArray::at: Absolute index 16 out of range
    segmentation fault

    (and I haven't used a "16" anywhere).

    Then I call a "p.drawConvexPolygon( pts );", with p being a QPainter.

    What I am trying to do is to draw a polygon with points at coordinates:
    (X = 240, Y = 210) (X = 260, Y = 230) (X = 300, Y = 150) and (X = 320, Y = 170).

    Please help.

    Mariane

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: addPoints or addPoint

    Try:
    Qt Code:
    1. QPointArray pts(4);
    2. pts.setPoints(0, 240, 210, 260, 230, 300, 150, 320, 170);
    To copy to clipboard, switch view to plain text mode 
    or
    Qt Code:
    1. QPointArray pts(4);
    2. pts.setPoint(0, 240, 210);
    3. pts.setPoint(1, 260, 230);
    4. pts.setPoint(2, 300, 150);
    5. pts.setPoint(3, 320, 170);
    To copy to clipboard, switch view to plain text mode 

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.