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:
float exp = (event->delta() / 240.0);
float factor = powf(3/4, exp);
scale(factor, 1.0);
float exp = (event->delta() / 240.0);
float factor = powf(3/4, exp);
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)
//just changed the line : scale(factor, 1.0) to:
item->setScale(factor);
//just changed the line : scale(factor, 1.0) to:
item->setScale(factor);
To copy to clipboard, switch view to plain text mode
and in my class derived from QGraphicsItem I added to methods:
void setScale(float factor);
void updateTransform();
//In their implementations I did:
void mygraphicsItem::setScale(float factor)
{
m_factor = factor;
updateTransform();
}
void mygraphicsItem::updateTransform()
{
QTransform transform;
transform.scale(m_factor, 1.0);
setTransform(transform);
}
void setScale(float factor);
void updateTransform();
//In their implementations I did:
void mygraphicsItem::setScale(float factor)
{
m_factor = factor;
updateTransform();
}
void mygraphicsItem::updateTransform()
{
QTransform transform;
transform.scale(m_factor, 1.0);
setTransform(transform);
}
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,
Bookmarks