Results 1 to 3 of 3

Thread: QGraphicsView resize not centered

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2013
    Posts
    321
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    9
    Thanked 8 Times in 8 Posts

    Default QGraphicsView resize not centered

    Hi,
    I have a QGraphicsView linked to a node graph, all works fine but one problem is there : the resize.
    The resize works good but when you resize, the QGraphicsView is not centered anymore.
    The behavior needed is to have the same view but with more space around.
    Is it possible to have that ? How can it be achieved ?
    Thanks for the help

    EDIT :
    Here one solution I have found if someone has the same problem, reimplement the resizeEvent of QGraphicsView :
    Qt Code:
    1. void CEditorNodeView::resizeEvent( QResizeEvent* event )
    2. {
    3. // Base class.
    4. QGraphicsView::resizeEvent( event );
    5.  
    6. // Get the old size.
    7. const QSize OldSize = event->oldSize();
    8.  
    9. // Map to scene.
    10. const QPointF CenterPos = mapToScene( OldSize.width() / 2, OldSize.height() / 2 );
    11.  
    12. // Center on the center pos.
    13. centerOn( CenterPos );
    14. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by Alundra; 7th November 2014 at 02:26.

Similar Threads

  1. QGraphicsView resize and zoom
    By giostau in forum Qt Programming
    Replies: 0
    Last Post: 29th May 2013, 14:03
  2. Replies: 3
    Last Post: 11th December 2011, 10:09
  3. Replies: 7
    Last Post: 1st December 2011, 16:24
  4. QGraphicsView won't update until resize
    By stevel in forum Qt Programming
    Replies: 1
    Last Post: 27th February 2009, 21:45
  5. getting QGraphicsView to resize
    By MrGarbage in forum Qt Programming
    Replies: 1
    Last Post: 22nd January 2008, 03:49

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.