How to add swipe gesture on QScrollArea widget ?
-
i want to add swipe gesture on QScrollArea. i want to catch event also. if any body know how to add swipe gesture on QScrollArea then let me know . i also want to know how to catch event of swipe up and down.
-
@Qt-embedded-developer
Are you on a touchscreen? If yes, are you sure it's driver delivers really touch events to the OS. Cheap touch screens rather simulate "single-touch" mouse events.https://doc.qt.io/qt-5/gestures-overview.html
If using mouse events you might want to check QScroller
-
QScrollArea * scroll_area = new QScrollArea( this ); scroll_area->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); scroll_area->horizontalScrollBar()->setEnabled( false ); QScroller::grabGesture( scroll_area, QScroller::LeftMouseButtonGesture ); QScrollerProperties properties = QScroller::scroller( scroll_area )->scrollerProperties(); QVariant overshoot_policy = QVariant::fromValue< QScrollerProperties::OvershootPolicy >( QScrollerProperties::OvershootAlwaysOff ); properties.setScrollMetric( QScrollerProperties::VerticalOvershootPolicy, overshoot_policy ); properties.setScrollMetric( QScrollerProperties::HorizontalOvershootPolicy, overshoot_policy ); QScroller::scroller( scroll_area )->setScrollerProperties( properties );
-
@Qt-embedded-developer you create an instance of QScroller::scroller and connect it to QScroller::stateChanged
-
@Qt-embedded-developer
QScroller * scroller = QScroller::scroller( scroll_area );
scroller->setScrollerProperties( properties );connect( scroller, &QScroller:: stateChanged, this, &yourFuncSlot );
-
@JoeCFD As per your suggestion i have used below code but in my case on scrolling the slot DisplayImageList1() is not getting called.
why stateChanged does not call my slot DisplayImageList1() ?
where is mistake done in below code to get desired slot call on scrolling using QScroller::LeftMouseButtonGesture ?
QScrollerProperties qScrollerProperties; QVariant overshootPolicy = QVariant::fromValue<QScrollerProperties::OvershootPolicy>(QScrollerProperties::OvershootAlwaysOff); qScrollerProperties.setScrollMetric(QScrollerProperties::VerticalOvershootPolicy, overshootPolicy); QScroller* qScroller = QScroller::scroller(ui->scrollArea); qScroller->grabGesture(ui->scrollArea, QScroller::LeftMouseButtonGesture); qScroller->setScrollerProperties(qScrollerProperties); QObject::connect(qScroller, SIGNAL(stateChanged(QScroller::State)), this, SLOT(DisplayImageList1()));
Note: Above question i asked because on scrolling inside QScrollArea i need to call DisplayImageList1().
-
@Qt-embedded-developer I think you are doing swipe of pictures. Check this example out:
https://code.qt.io/cgit/qt/qtbase.git/tree/examples/widgets/gestures/imagegestures?h=5.15