Qt如何重写QScrollArea的wheelEvent事件以实现图片的缩放功能?

各位大佬.
Hello, My Gods.
我的问题是酱婶儿滴.
This problem is about Qt event.

在QScrollArea中显示图片时,其默认有一个鼠标滚轮控制垂直滚动条滚动的事件。所以当我想重写wheelEvent事件之后,它总是会在滚动条滚到头的时候才实现图像的缩放操作,所以怎样才能控制让滚轮操作只影响图像缩放,不影响垂直滚轮嘞?
下面是wheelEvent的代码.

 private slots:
// Reimplement the wheelEvent() to Achieve Zoom in and Zoom out.      
void wheelEvent(QWheelEvent *e);

/**
 *  @BRIEF Reimplement wheelEvent()
 *  @param QWheelEvent: Event about mouse wheel
 */
void MatchWindowSingle::wheelEvent(QWheelEvent *e)
{
    // If numDegress > 0, then zoom in,
    // else, zoom out.
    // The scale control the picture's size.
    int numDegress = e->delta();    

    // Update ScrollArea 控制图片缩放的各个函数
    if (ui.sa_geoImage->hasFocus()){
        identityScaleFactor(&numDegress, &scaleFactor_MIN_g, &scaleFactor_g);
        updateScrollArea(&geoPic, ui.sa_geoImage, &geoImageLable, &scaleFactor_g);
    }else if (ui.sa_videoImage->hasFocus()){
        identityScaleFactor(&numDegress, &scaleFactor_MIN_v, &scaleFactor_v);
        updateScrollArea(&videoPic, ui.sa_videoImage, &videoImageLable, &scaleFactor_v);
    }
}

private slots:
// Reimplement the wheelEvent() to Achieve Zoom in and Zoom out.

void wheelEvent(QWheelEvent *e);

/**

  • @BRIEF Reimplement wheelEvent()
  • @param QWheelEvent: Event about mouse wheel
    */
    void MatchWindowSingle::wheelEvent(QWheelEvent *e)
    {
    // If numDegress > 0, then zoom in,
    // else, zoom out.
    // The scale control the picture's size.
    int numDegress = e->delta();

    // Update ScrollArea 控制图片缩放的各个函数
    if (ui.sa_geoImage->hasFocus()){
    identityScaleFactor(&numDegress, &scaleFactor_MIN_g, &scaleFactor_g);
    updateScrollArea(&geoPic, ui.sa_geoImage, &geoImageLable, &scaleFactor_g);
    }else if (ui.sa_videoImage->hasFocus()){
    identityScaleFactor(&numDegress, &scaleFactor_MIN_v, &scaleFactor_v);
    updateScrollArea(&videoPic, ui.sa_videoImage, &videoImageLable, &scaleFactor_v);
    }
    }

这边问题解决了 , 你不要用自动生成的QScrollArea.ui 而是自己new 一个QScrollArea 对象出来, 然后重载他的wheel事件就好了

wheelEvent 是virtual protected函数, 应该在protected下重新实现该函数.
protected:
void wheelEvent(QWheelEvent *e)