Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
Ask Question
I was using the
delta()
function from the
QWheelEvent
class to achieve the zoom in, zoom out. now it is
deprecated
, and they advise in the
documentation
to use
pixelDelta()
or
angleDelta()
instead, but they are
QPoint
objects!
can anybody please tell me how to replace this deprecated function with another ones?
void MapView::wheelEvent(QWheelEvent *event)
if(event->delta()>0)
if(m_scale < MAX_SCALE)
std::cout << m_scale << std::endl;
this->scale(ZOOM_STEP, ZOOM_STEP);
m_scale *= ZOOM_STEP;
else if(event->delta() < 0)
if(m_scale >= MIN_SCALE)
std::cout << m_scale << std::endl;
this->scale(1/ZOOM_STEP, 1/ZOOM_STEP);
m_scale *= 1/ZOOM_STEP;
The documentation of angleDelta
says that angleDelta().y()
will return the angle by which the vertical mouse wheel was rotated and angleDelta().x()
will return the angle by which the horizontal mouse wheel was rotated.
For zooming I'm assuming you will want to use vertical scrolling, so changing the conditions accordingly gives:
void MapView::wheelEvent(QWheelEvent *event)
if(event->angleDelta().y() > 0)
if(m_scale < MAX_SCALE)
std::cout << m_scale << std::endl;
this->scale(ZOOM_STEP, ZOOM_STEP);
m_scale *= ZOOM_STEP;
else if(event->angleDelta().y() < 0)
if(m_scale >= MIN_SCALE)
std::cout << m_scale << std::endl;
this->scale(1/ZOOM_STEP, 1/ZOOM_STEP);
m_scale *= 1/ZOOM_STEP;
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.