Results 1 to 5 of 5

Thread: QGraphicsView Current Center

  1. #1
    Join Date
    Jul 2007
    Posts
    39
    Thanks
    10

    Default QGraphicsView Current Center

    Hi

    I have a QGraphicsView that is showing a QGraphicsScene. When saving the view, I also want to save the current centerlocation on the view, so that I can make the view centerOn the same point.

    Is there any way to find the current center?

    Thanks
    Arjun

  2. #2
    Join Date
    Jul 2007
    Posts
    39
    Thanks
    10

    Default Re: QGraphicsView Current Center

    Hi all

    I figured it out.

    QPointF center = mapToScene(viewport()->rect().center()) gives the current scene point that is in the center of the view's viewport.

    Using centerOn(center) would do the trick.

  3. #3
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QGraphicsView Current Center

    Are there any possibilites to move (0,0) scene coordinate to center of scene parent widget?
    Qt 5.3 Opensource & Creator 3.1.2

  4. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsView Current Center

    See QGraphicsView::translate(). You can use this to translate view (0,0) to parent widget's center.

  5. #5
    Join Date
    Feb 2009
    Posts
    16
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Question Re: QGraphicsView Current Center

    In order to find the center of the view in scene coordinates, I had to do it in the following order:
    mapToScene(viewport()->rect()).boundingRect().center()
    mapToScene(viewport()->rect().center() produces incorrect results and for me were a little to the upper left.

    Can anyone help me understand why they are different?

  6. The following user says thank you to stretchtiberius for this useful post:

    veiovis (18th April 2016)

Similar Threads

  1. Distributing QT application for Mac OS
    By mb0 in forum Qt Programming
    Replies: 1
    Last Post: 31st May 2007, 18:59
  2. 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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.