网上看到的,外加部分自己搜索的,简单的记录下,笔记做的太杂了,需要整理下
函数的原型为:
[static] Qt::GestureType QScroller::grabGesture(QObject *target, QScroller::ScrollerGestureType scrollGestureType = TouchGesture)
其中参数QObject *target 指需要滑动的界面
其中参数QScroller::ScrollerGestureType scrollGestureType = TouchGesture //默认的手势
QScroller::TouchGesture
The gesture recognizer will only trigger on touch events. Specifically it will react on single touch points when using a touch screen and dual touch points when using a touchpad.QScroller::LeftMouseButtonGesture
The gesture recognizer will only trigger on left mouse button events.QScroller::MiddleMouseButtonGesture
The gesture recognizer will only trigger on middle mouse button events.QScroller::RightMouseButtonGesture
The gesture recognizer will only trigger on right mouse button events.
如果scrollGestureType被设置为TouchGesture,手势就会触发触摸事件。如果它被设置为一个LeftMouseButtonGesture, RightMouseButtonGesture或MiddleMouseButtonGesture,它会触发相应按钮的鼠标事件。
具体使用方法很简单:
注意:此种方式不支持手指在滑动条上进行拖动
QScroller::grabGesture(ui->scrollArea, QScroller::LeftMouseButtonGesture);
若需要手指在滑动条上也能够触摸滑动,则需要用下面的方式
QScroller::grabGesture(ui->scrollArea->viewport(),QScroller::LeftMouseButtonGesture);