An overview,

The QGraphicsView view can be zoomed in and out using the mouse wheel.

Second, the steps

Create a new class that inherits QGraphicsView and overrides the wheelEvent mouse wheelEvent.

#include

Three, code,

void GraphicsView::wheelEvent(QWheelEvent *event)
{
    // Get the distance of mouse wheel
    int wheelDeltaValue = event->delta(a);// Scroll up to zoom in
    if (wheelDeltaValue > 0)
    {
        this->scale(1.2.1.2);
    }  
    
    // Scroll down to zoom out
    else
    {
        this->scale(1.0 / 1.2.1.0 / 1.2); }}Copy the code