Results 1 to 5 of 5

Thread: QGraphicsLineItem moveBy() doesn't really move the line, why?

  1. #1
    Join Date
    Sep 2009
    Location
    Surrey, BC, Canada
    Posts
    110
    Thanks
    1
    Thanked 2 Times in 1 Post
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default QGraphicsLineItem moveBy() doesn't really move the line, why?

    Hi, all:

    My code is as simple as:

    Qt Code:
    1. QPointF end1 = dynamic_cast<QGraphicsLineItem*>(lineItem)->line().p1();
    2. QPointF end2 = dynamic_cast<QGraphicsLineItem*>(lineItem)->line().p2();
    3. std::cout << end1.x() << " " << end1.y() << std::endl;
    4. std::cout << end2.x() << " " << end2.y() << std::endl;
    5.  
    6. dynamic_cast<QGraphicsLineItem*>(lineItem)->moveBy(dx, dy); // I'm pretty sure dx and dy are not 0
    7.  
    8. end1 = dynamic_cast<QGraphicsLineItem*>(lineItem)->line().p1();
    9. end2 = dynamic_cast<QGraphicsLineItem*>(lineItem)->line().p2();
    10. std::cout << end1.x() << " " << end1.y() << std::endl;
    11. std::cout << end2.x() << " " << end2.y() << std::endl;
    To copy to clipboard, switch view to plain text mode 

    two outputs of end1/end2 are always the same. However, I'm expecting there should be some difference, right?
    Why moveBy() doesn't really move two end points of such a QGraphicsLineItem ?
    How can I successfully move the end points then?


    cheers
    Pei
    Welcome to Vision Open
    http://www.visionopen.com

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QGraphicsLineItem moveBy() doesn't really move the line, why?

    Quote Originally Posted by jiapei100 View Post
    two outputs of end1/end2 are always the same. However, I'm expecting there should be some difference, right?
    No, they should be the same. You're not changing the line, just moving it.

    Why moveBy() doesn't really move two end points of such a QGraphicsLineItem ?
    Because the line determines the bounding rect of the item, not its position.

    How can I successfully move the end points then?
    You can learn about the difference between graphics item coordinate space and position.

    If you have a long stick in your hand and you say that it starts "two metres from here" and ends "three metres from here" and you move two steps in whatever direction (still holding the stick), it still starts "two metres from here" and ends "three metres from here". It's just "here" that changed because you moved. The same if you call moveBy() -- you will see pos() change but not boundingRect() or line().
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Sep 2009
    Location
    Surrey, BC, Canada
    Posts
    110
    Thanks
    1
    Thanked 2 Times in 1 Post
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsLineItem moveBy() doesn't really move the line, why?

    Thank you wysota.
    Very clear explanation. Thanks ...

    Trying to play with QPainterPath these days, a bit tough.
    Any examples please?



    Cheers
    Pei

    Quote Originally Posted by wysota View Post
    No, they should be the same. You're not changing the line, just moving it.


    Because the line determines the bounding rect of the item, not its position.


    You can learn about the difference between graphics item coordinate space and position.

    If you have a long stick in your hand and you say that it starts "two metres from here" and ends "three metres from here" and you move two steps in whatever direction (still holding the stick), it still starts "two metres from here" and ends "three metres from here". It's just "here" that changed because you moved. The same if you call moveBy() -- you will see pos() change but not boundingRect() or line().
    Welcome to Vision Open
    http://www.visionopen.com

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QGraphicsLineItem moveBy() doesn't really move the line, why?

    Examples of what exactly?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Sep 2009
    Location
    Surrey, BC, Canada
    Posts
    110
    Thanks
    1
    Thanked 2 Times in 1 Post
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsLineItem moveBy() doesn't really move the line, why?

    Hi, wysota:

    ^_^
    Please refer to my topic at
    http://www.qtcentre.org/threads/5361...ges?highlight=
    or
    http://qt-project.org/forums/viewthread/25503/

    I want to drag and drop any 2D (later I'll do 3D) shapes, and hopefully, I can rotate, scale, translate this shape due to various mouse actions.

    I did some example, but for now, my program needs to select the shape first, then drag one end of the line to any place I specified. I don't think it's very convenient.
    I'm wondering if there are some examples for me to follow up.

    Thanks wysota !


    Best Regards
    Pei



    Quote Originally Posted by wysota View Post
    Examples of what exactly?
    Welcome to Vision Open
    http://www.visionopen.com

Similar Threads

  1. Replies: 4
    Last Post: 19th March 2014, 08:12
  2. How can I get a textCursor to move to a particular line?
    By aarelovich in forum Qt Programming
    Replies: 0
    Last Post: 22nd June 2010, 19:29
  3. SetFocus doesn't work on line edit.
    By bgougeon in forum Qt Programming
    Replies: 1
    Last Post: 9th June 2009, 06:27
  4. Why doesn't the line appear on my Image?
    By Gh0stR1der in forum Newbie
    Replies: 1
    Last Post: 18th April 2009, 23:42
  5. how to move cursor to specific line in Text
    By showhand in forum Qt Programming
    Replies: 1
    Last Post: 24th August 2006, 09:55

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.