[Solved] Qt 5.2 Android QScroller on QTableWidget clicks?



  • Hello,

    I just discovered that Qt 5.0 introduced a QtScroller class which is acting kinda nice, but It is a bit "touchy"

    Let me explain :

    When I swipe my finger, it's scrolling like it should but sometimes, with nothing different, my finger movement is considered as a click instead of a scroll

    Even weirder : When such thing happens, the selection follows my finger without even having to click

    There is the QScroller related code :

    @
    QScrollerProperties scroller_properties;
    scroller_properties.setScrollMetric(QScrollerProperties::MousePressEventDelay, QVariant(0.5));
    QScrollerProperties::setDefaultScrollerProperties(scroller_properties);

    QScroller::ScrollerGestureType gesture = QScroller::LeftMouseButtonGesture;
    QScroller::grabGesture(ui->arretTable, gesture);
    QScroller::grabGesture(ui->ligneTable, gesture);
    QScroller::grabGesture(ui->passageTable, gesture);
    QScroller::grabGesture(ui->horaireTable, gesture);
    

    @

    PS : I had to make the gesture "LeftMouseButtonGesture" because "TouchGesture" clicked everytime instead of scrolling

    Edit : Forgot to mention : This behaviour only occurs on Android, when testing on my desktop,it never happens



  • Hey,

    try setting QScrollerProperties::MaximumClickThroughVelocity to 0, then you should be able to use TouchGesture as the gesture without sending a click every time you scroll.

    My solution for the problem where the selection follows your finger, is to set the table selection mode to QAbstractItemView::NoSelection with QTableWidget::setSelectionMode. Then, instead of QTableWidgetItems, you insert your own custom widgets using QTableWidget::setCellWidget.

    If you need to, you can reimplement QWidget::event in the custom widget and handle your touch events there any way you like.

    Hope this helps.

    UPDATE:

    I started fiddling with the scroller and found out that it's actually better to use LeftMouseButtonGesture as the scroller gesture than TouchGesture on Android.

    While using TouchGesture, the item selection while dragging also happens when you are scrolling, which results in pretty buggy behavior. With LeftMouseButton, the selection happens only when you are not scrolling.

    Item selection still happens the same way on desktop when holding the left mouse button and moving through items (when not scrolling), so I think that is intended behavior.

    Using the following QScrollerProperties I have been able to minimize the click through when trying to do a swipe gesture:

    @ QScrollerProperties sp;

    sp.setScrollMetric(QScrollerProperties::DragVelocitySmoothingFactor, 0.6);
    sp.setScrollMetric(QScrollerProperties::MinimumVelocity, 0.0);
    sp.setScrollMetric(QScrollerProperties::MaximumVelocity, 0.5);
    sp.setScrollMetric(QScrollerProperties::AcceleratingFlickMaximumTime, 0.4);
    sp.setScrollMetric(QScrollerProperties::AcceleratingFlickSpeedupFactor, 1.2);
    sp.setScrollMetric(QScrollerProperties::SnapPositionRatio, 0.2);
    sp.setScrollMetric(QScrollerProperties::MaximumClickThroughVelocity, 0);
    sp.setScrollMetric(QScrollerProperties::DragStartDistance, 0.001);
    sp.setScrollMetric(QScrollerProperties::MousePressEventDelay, 0.5);
    QScroller* scroller = QScroller::scroller(myTableWidget);
    
    scroller->grabGesture(myTableWidget, QScroller::LeftMouseButtonGesture);
    
    scroller->setScrollerProperties(sp);@
    

    It still happens sometimes, but more rarely.



  • Thank you for your help, I'll try it as soon as possible and will edit this post to let you know if it worked :)

    EDIT :

    Thank you so much ! This works just fine ! :)



  • Awesome! Happy to help.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.