Results 1 to 2 of 2

Thread: What's the difference? (QLineF, pos, setPoints())

  1. #1
    Join Date
    Apr 2009
    Location
    Valencia (Spain)
    Posts
    245
    Thanks
    38
    Thanked 19 Times in 19 Posts
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default What's the difference? (QLineF, pos, setPoints())

    Hi, I have an app with a QGraphicsScene and a button.

    If the user clicks the button, and clicks later on the scene, a QGraphicsLine is created, the final point of the line "follows" the pointer and when the user clicks again the last point is settled. In a nutshell, the normal behavior in any vector graphics editor.

    I first tried with this code:

    Qt Code:
    1. QGraphicsLineItem* create(QPointF initPoint, QPointF finalPoint)
    2. {
    3. pLine->line().setPoints(pLine->initPoint, finalPoint);
    4. m_pScene->addItem(pLine );
    5. return pLine;
    6. }
    To copy to clipboard, switch view to plain text mode 

    The final point of the line is changed in its paint method.

    BUT all the QGraphcsLineItem I created started in the same starting point (of course, "initPoint" was always different). And I'm 100% sure it wasn't changed at all in any part of my code.

    So I tried this code:

    Qt Code:
    1. QGraphicsLineItem* create(QPointF initPoint, QPointF finalPoint)
    2. {
    3. QLineF auxLine(initPoint, finalPoint);
    4. pLine->setLine(auxLine);
    5. m_pScene->addItem(pLine );
    6. return pLine;
    7. }
    To copy to clipboard, switch view to plain text mode 


    And it works!!!

    I would like to ask you if you know what could have been going wrong with the first code... I tried few things, like setting it's post mapped from scene, and mapping different coords... but no success.

    thanks!

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: What's the difference? (QLineF, pos, setPoints())

    QGraphicsLineItem::line() doesn't return a pointer/reference with which you could change the coordinates of the QGraphicsLineItem. It only returns a copy. So all changes you are made are lost.

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

    jano_alex_es (28th October 2009)

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.