very hard to read, please add [Code] tags
Added after 10 minutes:
Looks like you are not geting the calculations correct, check the following
{
// Typical Calculations (Ref Qt Doc)
const int degrees = event->delta() / 8;
int steps = degrees / 15;
// Declare below as class member vars and set default values as below
// qreal h11 = 1.0
// qreal h12 = 0
// qreal h21 = 1.0
// qreal h22 = 0
double scaleFactor = 1.0; //How fast we zoom
const qreal minFactor = 1.0;
const qreal maxFactor = 10.0;
if(steps > 0)
{
h11 = (h11 >= maxFactor) ? h11 : (h11 + scaleFactor);
h22 = (h22 >= maxFactor) ? h22 : (h22 + scaleFactor);
}
else
{
h11 = (h11 <= minFactor) ? minFactor : (h11 - scaleFactor);
h22 = (h22 <= minFactor) ? minFactor : (h22 - scaleFactor);
}
ui
->graphicsView
->setTransformationAnchor
(QGraphicsView::AnchorUnderMouse);
ui->graphicsView->setTransform(QTransform(h11, h12, h21, h22, 0, 0));
}
void Widget::wheelEvent(QWheelEvent* event)
{
// Typical Calculations (Ref Qt Doc)
const int degrees = event->delta() / 8;
int steps = degrees / 15;
// Declare below as class member vars and set default values as below
// qreal h11 = 1.0
// qreal h12 = 0
// qreal h21 = 1.0
// qreal h22 = 0
double scaleFactor = 1.0; //How fast we zoom
const qreal minFactor = 1.0;
const qreal maxFactor = 10.0;
if(steps > 0)
{
h11 = (h11 >= maxFactor) ? h11 : (h11 + scaleFactor);
h22 = (h22 >= maxFactor) ? h22 : (h22 + scaleFactor);
}
else
{
h11 = (h11 <= minFactor) ? minFactor : (h11 - scaleFactor);
h22 = (h22 <= minFactor) ? minFactor : (h22 - scaleFactor);
}
ui->graphicsView->setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
ui->graphicsView->setTransform(QTransform(h11, h12, h21, h22, 0, 0));
}
To copy to clipboard, switch view to plain text mode
Bookmarks