Results 1 to 2 of 2

Thread: Zoom in a QgraphicsView using pushbutton

  1. #1

    Default Zoom in a QgraphicsView using pushbutton

    I'm building a very simple image editor on Qt creator.I have my image displayed on a QGraphicsView and i want to give the user the ability to zoom in and out by a pushbutton.

    I've searched a lot and found how to zoom in and out through the mouse wheel.As i am very new to Qt i can't adjust it to the pushbutton because i don't understand everything clearly.

    I' ve tried this(without understanding completely what i'm doing)but the result isn't the wanted.It zooms in only once and quite abruptly.I want a smoother zoom and as many times as i want.

    Qt Code:
    1. void MainWindow::on_pushButton_clicked(){
    2. QMatrix matrix;
    3. ui->graphicsView->setTransformationAnchor(QGraphicsView::AnchorViewCenter);
    4. matrix.scale(1.0,1.0);
    5. ui->graphicsView->setMatrix(matrix);
    6. ui->graphicsView->scale(1,-1);}
    To copy to clipboard, switch view to plain text mode 

    I would be very grateful if you guys can help!

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Zoom in a QgraphicsView using pushbutton

    In order to zoom you need to scale by values not equal to 1.

    Scaling is basically muliplying values, scaling by 1 means no change.
    E.g. if you want to make things twice as large as they are now, scale by 2 in both axis.

    Cheers,
    _

Similar Threads

  1. QGraphicsView resize and zoom
    By giostau in forum Qt Programming
    Replies: 0
    Last Post: 29th May 2013, 14:03
  2. Qgraphicsview zoom issue
    By tarunrajsingh in forum Qt Programming
    Replies: 6
    Last Post: 23rd April 2013, 11:28
  3. Zoom functionality on pushbutton
    By chirudi in forum Qt Programming
    Replies: 7
    Last Post: 8th January 2013, 07:02
  4. QGraphicsView - zoom out using the right mouse button
    By dbrmik in forum Qt Programming
    Replies: 1
    Last Post: 14th April 2009, 22:17
  5. missing image with zoom (QGraphicsView)
    By avis_phoenix in forum Qt Programming
    Replies: 7
    Last Post: 18th March 2009, 13:09

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.