Results 1 to 4 of 4

Thread: QGraphicsView.AnchorViewCenter inconsistency ?

  1. #1
    Join Date
    May 2009
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QGraphicsView.AnchorViewCenter inconsistency ?

    I have a scene that I want to show an overview on (=zoom out), keeping my current center position.

    view.setTransformationAnchor(QGraphicsView.AnchorV iewCenter)
    zoom = QTransform()
    zoom.scale(zoom_out_factor)
    view.setTransformation(zoom)

    Now, this almost works. If my coordinates are large, all is well. The trouble starts if the viewport would have to show sub-zero coordinates to satisfy the transform. Instead of extending, it just clips the scene at 0, which in turn results in the whole scene drifting off-center.

    Example: if I'm looking at QRect(100,100,40,40), after the transform I'll be looking at QRect(90,90,60,60), which is OK. However, If I start at QRect(0,0,40,40), the result is QRect(0,0,60,60) and not the desired QRect(-10,-10,60,60).

    Is there any elegant way around this ? I'm using setSceneRect() or inserting dummy elements at extreme cordinates to avoid this clipping, but I keep thinking there must be a better way

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

    Default Re: QGraphicsView.AnchorViewCenter inconsistency ?

    What is your scene's rectangle?
    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
    May 2009
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsView.AnchorViewCenter inconsistency ?

    Quote Originally Posted by wysota View Post
    What is your scene's rectangle?
    For example QRect(0,0,2000,500)

    I'd like to keep the center (whereever it is) when I zoom out. However, as it is now, on zooming out when the upper left corner reaches 0,0 the AnchorViewCenter breaks -> it keeps 0,0 at top left causing the whole view to slide. If I do a setSceneRect() with extreme values, or insert dummy QGraphicsItems on the corners of the zoomed out view, it works, but that's an ugly workaround

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

    Default Re: QGraphicsView.AnchorViewCenter inconsistency ?

    What happens if you call:
    Qt Code:
    1. view->fitInView(view->sceneRect());
    To copy to clipboard, switch view to plain text mode 
    ?
    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. QListWidget - inconsistency across operating systems?
    By scwizard in forum Qt Programming
    Replies: 20
    Last Post: 20th February 2007, 01:45

Tags for this Thread

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.