Tonyimo 2017-12-10 14:46 采纳率: 0%
浏览 4118
已结题

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);
    }
}

  • 写回答

3条回答 默认 最新

  • weixin_41344553 2017-12-10 15:00
    关注

    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);
      }
      }

    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器