Hello,

I reimplemented the wheelEvent in my graphicsView class to be able to zoom in and zoom out smoothly in width of an image. At first the implementation was:

Qt Code:
  1. float exp = (event->delta() / 240.0);
  2. float factor = powf(3/4, exp);
  3. scale(factor, 1.0);
To copy to clipboard, switch view to plain text mode 

This works great, except that I don't want to be able to zoom out too much that the image starts being smaller than the widget that contains it. I want the container widget rectangle to be the minimum width of the image.

For this I tried using transforms the following way:
In the wheel event I did this instead:
(item is my GraphicsItem object)

Qt Code:
  1. //just changed the line : scale(factor, 1.0) to:
  2. item->setScale(factor);
To copy to clipboard, switch view to plain text mode 

and in my class derived from QGraphicsItem I added to methods:

Qt Code:
  1. void setScale(float factor);
  2. void updateTransform();
  3.  
  4. //In their implementations I did:
  5.  
  6. void mygraphicsItem::setScale(float factor)
  7. {
  8. m_factor = factor;
  9. updateTransform();
  10. }
  11.  
  12. void mygraphicsItem::updateTransform()
  13. {
  14. QTransform transform;
  15. transform.scale(m_factor, 1.0);
  16. setTransform(transform);
  17. }
To copy to clipboard, switch view to plain text mode 

Now the part to prevent and control the zooming is not implemented yet since I am jsut testing this, but shouldn't something like this do the same thing as before when I was scaling the view instead of the item?

Am I remotely on the right track to accomplish what I want? How can this be done?

Thanks!

This last way does nothing like before,