添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
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

How to replace the deprecated function `QWheelEvent::delta()` in the zoom in / zoom out function?

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;
                NB Qt docs clarify the horizontal/vertical QPoint structure 5.15, but if you're like me and are using, say, 5.9 they do not (5.12 has the same doc. issue).  So if you're, say, using CentOS 7 and Qt Creator's local help docs you're not crazy and you didn't miss something obvious.
– eclarkso
                Jun 8, 2022 at 13:44
        

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.