• qt触控板手势检测


    1、代码在mac上经过测试无问题;
    2、windows上面支持双指上下、左右滑动检测,不支持缩放手势检测
    3、窗口为popup模式下,不支持QEvent::NativeGesture事件;

    1、检测双指上下滚动、左右滚动

    bool WBScreenShotDialog::event(QEvent *event)
    {
        if (event->type() == QEvent::Wheel) {   // 双指滚动
            QWheelEvent *wheel = static_cast<QWheelEvent *>(event);
            if (wheel->phase() != Qt::ScrollEnd) {
                QPointF angleDelta = wheel->angleDelta();  //滚轮度数的增量
                qreal xOffset = angleDelta.x();
                qreal yOffset = angleDelta.y();
                /// y轴缩放:y轴变动大于0,且y轴变动大于x轴
                bool yZoom = (qAbs(yOffset) > 0) && (qAbs(yOffset) > qAbs(xOffset));
                if (yZoom) {    /// 触控板Y方向滚动(双指滑动)
                    updateImageSize(yOffset > 0 ? 1.02 : 0.98);
                    updateRect();
                    update();
                } else {    /// 触控板X方向滚动(双指滑动)
    
                }
            }
            return true;
        }
        return QDialog::event(event);
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22

    2、双指放大、缩小检测

    bool WBScreenShotDialog::event(QEvent *event)
    {
        if (event->type() == QEvent::NativeGesture) {  /// 双指缩放
            QNativeGestureEvent *nge = static_cast<QNativeGestureEvent *>(event);
            if (nge->gestureType() == Qt::ZoomNativeGesture) {
                double factor = nge->value() * 100;
                if (factor != 0.){
                    updateImageSize(factor > 0 ? 1.02 : 0.98);
                    updateRect();
                    update();
                }
            }
            return true;
        }
        return QDialog::event(event);
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
  • 相关阅读:
    [工具]工控机磁盘容量监控通知工具
    简单实现spring的set依赖注入
    需要在js中避免的几个常见错误
    第五节 Electron 模块介绍 remote模块详细介绍
    vue首页多模块布局(标题布局)
    单目操作符
    python_unittest
    宝塔composer 安装laravel依赖出现的问题
    maven基础
    DDoS报告团伙规模
  • 原文地址:https://blog.csdn.net/weixin_42887343/article/details/132732474