Results 1 to 2 of 2

Thread: FitInView is not allowing me to zoom GraphicsScene

  1. #1
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default FitInView is not allowing me to zoom GraphicsScene

    Hi Friends,

    I made a QGraphicsView of size (0, 0, 1024, 1024)
    and QGraphicsScene of size (0, 0, 2048, 2048)

    i drawn some grid lines on the scene using
    drawForeground(QPainter *painter, const QRectF &rect)

    and now to make the scene to fit with the view
    i used

    Qt Code:
    1. View::resizeEvent(QResizeEvent *event)
    2. {
    3. QGraphicsView::resizeEvent(event);
    4. fitInView(scene()->sceneRect(), Qt::KeepAspectRatio);
    5. }
    To copy to clipboard, switch view to plain text mode 

    and then i implemented zoom in the scene with

    Qt Code:
    1. void View::wheelEvent(QWheelEvent *e)
    2. {
    3.  
    4. qreal factor = pow((double)2, -e->delta() / 240.0);
    5.  
    6. zoom(factor);
    7. }
    8.  
    9. void View::zoom(qreal factor)
    10. {
    11.  
    12.  
    13. scale(factor, factor);
    14.  
    15. }
    To copy to clipboard, switch view to plain text mode 

    this zooming is not working for enlarging .
    if i remove the fitInView it allowing to zoom but scene looks bigger than view .

    Please help me

    Thanks in Advance
    "Behind every great fortune lies a crime" - Balzac

  2. #2
    Join Date
    Mar 2013
    Posts
    11
    Thanks
    6
    Qt products
    Qt4 Qt5
    Platforms
    Windows Android

    Default Re: FitInView is not allowing me to zoom GraphicsScene

    I tried your code ,,,its working fine ..I am able to enlarge without removing fitinView from resizeevent handler.

Similar Threads

  1. Allowing connections outside of LAN
    By ben1996123 in forum Qt Programming
    Replies: 22
    Last Post: 10th December 2012, 19:29
  2. QGraphicsView::fitInView()
    By stella1016 in forum Qt Programming
    Replies: 3
    Last Post: 30th March 2011, 18:49
  3. QActionGroup allowing unchecking ?
    By divide in forum Qt Programming
    Replies: 0
    Last Post: 29th June 2010, 14:16
  4. transfer graphicsscene on form1 to graphicsscene on form2
    By rogerholmes in forum Qt Programming
    Replies: 2
    Last Post: 25th September 2009, 20:37
  5. QTable - allowing it to only enter ints
    By therealjag in forum Qt Programming
    Replies: 2
    Last Post: 14th February 2006, 17:33

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.