Results 1 to 2 of 2

Thread: Scaling a QGraphicsPixmapItem in a QGraphicsScene/View

  1. #1
    Join Date
    Jan 2011
    Posts
    22
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Scaling a QGraphicsPixmapItem in a QGraphicsScene/View

    Hello,

    I have a scene that can have multiple QGraphicsPixmapItems in it, which I have overridden to call ImagePixmapItem.

    I want to make it so that the item that has mouse focus will respond to wheel events, allowing a user to scoll up and back with the wheel mouse whcih will zoom the image. This is currently working fine, except that using code like:

    Qt Code:
    1. qreal factor = 1.2;
    2. if (event->delta() < 0)
    3. factor = 1.0 / factor;
    4.  
    5. this->setTransform(QTransform::fromScale(factor,factor), true);
    6. this->setScaleFactor(scaleFactor*factor);
    To copy to clipboard, switch view to plain text mode 

    Makes the image always zoom from the upper left corner. Since the size of the original images is approx 4000x5000, this can get cumbersome, because if you're viewing the zoomed out version, on say the bottom right corner, every time you zoom in, it shifts down and to the right (since it seems to be scaling from 0,0), and thus you have to zoom, then pan, then zoom, them pan, etc. I want to be able to zoom the image and then translate it so that the the area under the mouse is the same before and after the zoom.

    I tried to use a couple of different things like:
    1)
    this->setTransformOriginPoint(event->pos());
    this->setTransform(QTransform::fromScale(factor,factor) , true);
    2)
    this->setTransform(QTransform::fromTranslate(event->scenePos().x(), event->scenePos().y()));
    3)
    this->setTransform(QTransform::fromTranslate(event->pos().x(), event->pos().y()));

    But this sems to give all manner of terrible results.

    What is the proper way to do this? I dont want to just zoom the view, beacause that will zoom every image in the scene, and I will have more than one present. Is there a way from wtihin the ImagePixmapItem to zoom under the mouse, performing the proper transformations that will keep the area of interest on the screen while zooming in and out?

    Thanks

    Derek

  2. #2
    Join Date
    Jan 2011
    Posts
    22
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Scaling a QGraphicsPixmapItem in a QGraphicsScene/View

    bump..no one has any ideas?

Similar Threads

  1. General advice about scaling on QGraphicsView/QGraphicsScene
    By onurozcelik in forum Qt Programming
    Replies: 0
    Last Post: 24th May 2010, 08:14
  2. QGraphicsPixmapItem to QGraphicsScene
    By strateng in forum Newbie
    Replies: 5
    Last Post: 27th March 2010, 01:50
  3. Scaling too much on a graphics view
    By natnan in forum Qt Programming
    Replies: 5
    Last Post: 15th September 2009, 12:48
  4. Scaling QGraphicsPixmapItem
    By johnsoga in forum Qt Programming
    Replies: 9
    Last Post: 7th May 2009, 17:04
  5. Ignoring scaling graphics view/scale
    By maverick_pol in forum Qt Programming
    Replies: 1
    Last Post: 7th August 2007, 17:44

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.