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