Hi!
You should reimplement the QGraphicsView::wheelEvent ( QWheelEvent * event )
This code work fine.
header:
#include <QGraphicsView>
{
Q_OBJECT
public:
GeoMapGraphicsView
(QWidget *parent
= 0);
void zoom
(qreal factor,
QPointF centerPoint
);
protected:
private:
bool isTouched;
};
#include <QGraphicsView>
class GeoMapGraphicsView : public QGraphicsView
{
Q_OBJECT
public:
GeoMapGraphicsView(QWidget *parent = 0);
void zoom(qreal factor, QPointF centerPoint);
protected:
void wheelEvent ( QWheelEvent * event );
private:
bool isTouched;
QPointF mousePos;
};
To copy to clipboard, switch view to plain text mode
in source:
{
if (e->modifiers().testFlag(Qt::ControlModifier)){ // zoom only when CTRL key pressed
int numSteps = e->delta() / 15 / 8;
if (numSteps == 0) {
e->ignore();
return;
}
qreal sc = pow(1.25, numSteps); // I use scale factor 1.25
this->zoom(sc, mapToScene(e->pos()));
e->accept();
}
}
void GeoMapGraphicsView
::zoom(qreal factor,
QPointF centerPoint
) {
scale(factor, factor);
centerOn(centerPoint);
}
void GeoMapGraphicsView::wheelEvent ( QWheelEvent * e)
{
if (e->modifiers().testFlag(Qt::ControlModifier)){ // zoom only when CTRL key pressed
int numSteps = e->delta() / 15 / 8;
if (numSteps == 0) {
e->ignore();
return;
}
qreal sc = pow(1.25, numSteps); // I use scale factor 1.25
this->zoom(sc, mapToScene(e->pos()));
e->accept();
}
}
void GeoMapGraphicsView::zoom(qreal factor, QPointF centerPoint)
{
scale(factor, factor);
centerOn(centerPoint);
}
To copy to clipboard, switch view to plain text mode
Bookmarks