Results 1 to 8 of 8

Thread: QGraphicsView: determining the current scale factor

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2008
    Posts
    88
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11
    Thanks
    4
    Thanked 4 Times in 3 Posts
    Wiki edits
    1

    Default Re: QGraphicsView: determining the current scale factor

    Thats a good point the painter does have a level of detail property that could be used for this.

    My situation is rather simple since I'm just scaling then entire view, not individual items.

    So when I'm using fitToView it scales the view to the sceneBoundingRect() of the item. The kicker is then if I want to zoom in or out from that point I have to start with a relative scale factor. Thats where the level of detail comes in play.

    I also just took a peek at the QGraphicsView source and this is peppered throughout the code:
    Qt Code:
    1. // Find the ideal x / y scaling ratio to fit \a source into \a target.
    2. qreal xratio = targetRect.width() / sourceRect.width();
    3. qreal yratio = targetRect.height() / sourceRect.height();
    4.  
    5. // Scale according to the aspect ratio mode.
    6. switch (aspectRatioMode) {
    7. case Qt::KeepAspectRatio:
    8. xratio = yratio = qMin(xratio, yratio);
    9. break;
    10. case Qt::KeepAspectRatioByExpanding:
    11. xratio = yratio = qMax(xratio, yratio);
    12. break;
    13. case Qt::IgnoreAspectRatio:
    14. break;
    15. ...
    16. painterMatrix *= QTransform()
    17. .translate(targetRect.left(), targetRect.top())
    18. .scale(xratio, yratio)
    19. .translate(-sourceRect.left(), -sourceRect.top());
    20. }
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: QGraphicsView: determining the current scale factor

    Quote Originally Posted by chezifresh View Post
    The kicker is then if I want to zoom in or out from that point I have to start with a relative scale factor. Thats where the level of detail comes in play.
    This one you can keep yourself in the view and update it every time you zoom the view. You don't need to know the transforms of individual items.
    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.


Similar Threads

  1. QGraphicsView Current Center
    By arjunasd in forum Qt Programming
    Replies: 4
    Last Post: 8th November 2010, 20:49
  2. Can I get current rotation of a QGraphicsView?
    By bjh in forum Qt Programming
    Replies: 5
    Last Post: 2nd October 2008, 22:04
  3. Problem determining size of QGraphicsView
    By Bocki in forum Qt Programming
    Replies: 3
    Last Post: 17th February 2008, 14:54
  4. Distributing QT application for Mac OS
    By mb0 in forum Qt Programming
    Replies: 1
    Last Post: 31st May 2007, 18:59
  5. Replies: 15
    Last Post: 21st April 2007, 17:46

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
  •  
Qt is a trademark of The Qt Company.