Results 1 to 3 of 3

Thread: Do not move QGraphicsItem after scaling

  1. #1
    Join Date
    Jul 2016
    Posts
    19
    Thanks
    9
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Do not move QGraphicsItem after scaling

    Hello,
    In my QGraphicsScene I have a QGraphicsItem ( the red rectangle) and a QGraphicsLineItem. I can also change the scale of the view but my QGraphicsLineItem ignores the scale changes : to achieve that I used the following line of code:

    Qt Code:
    1. myQGraphicsLineItem->setScale(1.0/scaleOfView);
    To copy to clipboard, switch view to plain text mode 

    So the two items don't have the same scale.
    Unfortunately when the scale of the view changes, the relative position of my two items changes ( see the two captures) even if the scene positions of the two items remain the same . Do you understand why ?

    Capture2.JPGCapture1.JPG


    Thank you

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Do not move QGraphicsItem after scaling

    Very likely an issue with the transformation anchor.

    When you scale manually you are probably scaling from the center of the item, not from the top left.

    Cheers,
    _

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

    nilot (28th September 2016)

  4. #3
    Join Date
    Jul 2016
    Posts
    19
    Thanks
    9
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Do not move QGraphicsItem after scaling

    Hello,
    I added this line

    Qt Code:
    1. myQGraphicsLineItem->setTransformOriginPoint(topLeftPointOfTheLine);
    To copy to clipboard, switch view to plain text mode 

    and it works well, thank you.

Similar Threads

  1. QGraphicsItem move only on certain condition
    By pratham_shah in forum Qt Programming
    Replies: 3
    Last Post: 29th April 2013, 09:54
  2. QGraphicsItem move
    By Ichi in forum Qt Programming
    Replies: 1
    Last Post: 19th April 2013, 19:48
  3. Replies: 2
    Last Post: 25th March 2011, 09:18
  4. QGraphicsItem scaling behaviour?
    By kachofool in forum Qt Programming
    Replies: 2
    Last Post: 1st January 2011, 18:17
  5. Scale size of QGraphicsItem without scaling pen width
    By Lodorot in forum Qt Programming
    Replies: 1
    Last Post: 25th May 2009, 00:18

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.