Results 1 to 2 of 2

Thread: QGraphicsLineItem - setting its points

  1. #1
    Join Date
    May 2013
    Posts
    13
    Thanks
    4

    Default QGraphicsLineItem - setting its points

    Hello,

    I 'm looking to have a QGraphicsLineItem and be able to move either of its points. Between its position and its QLine, I 've failed to determine an effective way of accomplishing this. In particular, I am baffled as to why this prints both points at 0,0:

    Qt Code:
    1. #include <QGraphicsLineItem>
    2. #include <QDebug>
    3.  
    4. int main()
    5. {
    6. item->line().setP1(QPointF(10, 10));
    7. qDebug() << item->line();
    8. }
    To copy to clipboard, switch view to plain text mode 

    Any clues would be welcome.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QGraphicsLineItem - setting its points

    Line 7: item->line() returns a temporary copy of the item's internal QLineF object. You modify that temporary object and then it is discarded.
    Line 8: Prints the content of another (unchanged) copy of the line.

    Qt Code:
    1. // To set both line ends
    2. item->setLine(QLineF(QPointF(10, 10), QPointF(20, 20)));
    3. qDebug() << item->line();
    4.  
    5. // To move one end of the line
    6. QLineF line = item->line();
    7. line.setP1(QPointF(30, 30));
    8. item->setLine(line);
    9. qDebug() << item->line();
    To copy to clipboard, switch view to plain text mode 

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

    Durkin (5th March 2014)

Similar Threads

  1. Replies: 2
    Last Post: 2nd May 2012, 09:49
  2. How do i get QGraphicsLineItem coordinates?
    By chaltier in forum Qt Programming
    Replies: 1
    Last Post: 2nd April 2012, 05:41
  3. QGraphicsLineItem - selection style
    By stefan in forum Qt Programming
    Replies: 5
    Last Post: 29th November 2010, 09:02
  4. Setting the QGraphicsLineItem tickness.....
    By dreamer in forum Qt Programming
    Replies: 1
    Last Post: 9th July 2008, 12:11
  5. QGraphicsLineItem + setAcceptHoverEvents
    By NoRulez in forum Qt Programming
    Replies: 2
    Last Post: 13th May 2008, 12:13

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.