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

    评论

报告相同问题?

悬赏问题

  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题