Results 1 to 3 of 3

Thread: QGraphicsItem: ignore scaling without ignoring rotations

  1. #1
    Join Date
    May 2009
    Posts
    21
    Thanks
    4
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QGraphicsItem: ignore scaling without ignoring rotations

    Hi,

    I've got a QGraphicsView which allows translations, rotations and scaling and there are some QGraphicsItem I want to ignore the scaling.

    If I set QGraphicsItem::ItemIgnoresTransformations all rotation, zoom or shear transformations are ignored. Is there a way to keep the size of a QGraphicsItem fixed without ignoring all transformations.

    Does the QGraphicsItem gets informed when the QGraphicsView calls scale, so that I can react on the scaling and scale the QGraphicsItem back.

    Thank you in advance

    Markus

    PS: I'm using Qt 4.5.1.

  2. #2
    Join Date
    May 2009
    Posts
    62
    Thanks
    2
    Thanked 16 Times in 15 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsItem: ignore scaling without ignoring rotations

    I would keep a list of all items that you don't want to scale, and then do this for scaling:

    Qt Code:
    1. QList<QGraphicsItem*> nonScalingItems;
    2.  
    3. // ...
    4.  
    5. view->scale(scaleX, scaleY);
    6. foreach (QGraphicsItem* item, nonScalingItems)
    7. {
    8. item->scale(1.0/scaleX, 1.0/scaleY);
    9. }
    To copy to clipboard, switch view to plain text mode 

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

    Lodorot (4th July 2009)

  4. #3
    Join Date
    Mar 2011
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QGraphicsItem: ignore scaling without ignoring rotations

    Hi

    What I've done to solve this problem
    Note: myGraphicsView->initialScale is != to 1.f in my application but for most of code, you can replaced it by 1;
    Qt Code:
    1. MyItem::MyItem(QGraphicsView* _myGraphicsView )
    2. {
    3. myGraphicsView = _myGraphicsView;
    4. connect(myGraphicsView ,SIGNAL(scaleChanged(float)),this,SLOT(parentScaleChanged(float)));
    5. }
    6.  
    7. void MyItem::parentScaleChanged(float newScale)
    8. {
    9. setScale(myGraphicsView->initialScale/newScale);
    10. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Scale size of QGraphicsItem without scaling pen width
    By Lodorot in forum Qt Programming
    Replies: 1
    Last Post: 25th May 2009, 00:18
  2. Ignoring scaling graphics view/scale
    By maverick_pol in forum Qt Programming
    Replies: 1
    Last Post: 7th August 2007, 17:44
  3. Replies: 6
    Last Post: 30th April 2007, 23:59
  4. how to corss compile for windows in Linux
    By safknw in forum Qt Programming
    Replies: 24
    Last Post: 13th May 2006, 05:23

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.