Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [mobile][touch events] How to scroll listwidget after "flicking" on device?
Forum Updated to NodeBB v4.3 + New Features

[mobile][touch events] How to scroll listwidget after "flicking" on device?

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 716 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Snorkelbuckle
    wrote on last edited by Snorkelbuckle
    #1

    Developing for android smartphones, I've got a QListWidget that shows items and I just want to allow users to scroll the list by swiping up or down anywhere in the list, not just on the scrollbar. I've installed my event filter and I can capture TouchEvents and I can scroll, but my problem is that as soon as user is no longer touching the device, the scroll stops dead. I want it to be like most other mobile apps that allow the list to continue scrolling, after finger is lifted, for a short distance depending on how fast the user swiped.

    Does anybody have any idea how this can be done?

    Here is relevant excerpt from my event filter, once I've accepted the TouchBegin event, I perform the scrolling in the TouchUpdate event. I'm guessing I should do the scrolling after user lifts finger in TouchEnd event, but I have no idea how I would do that, how does one capture the speed and direction at which user swiped?

        case QEvent::TouchUpdate:
        {
            touchEvent = static_cast<QTouchEvent*>(event);
            QTouchEvent::TouchPoint tp = touchEvent->touchPoints()[0];
            
            QPointF lastpos = tp.lastPos();
            QPointF curpos = tp.pos();
            qreal dy = curpos.y() - lastpos.y();
            int crnt = ui->myList->verticalScrollBar()->value();
            ui->myList->verticalScrollBar()->setValue(crnt - dy);
    
            return true;
        }
    

    Thanks.

    1 Reply Last reply
    0
    • AndySA Offline
      AndySA Offline
      AndyS
      Moderators
      wrote on last edited by
      #2

      Hi @Snorkelbuckle,

      I suggest you take a look at QScroller, if you have this call grabGesture() on the QListWidget's viewport then it should give you what you want without having to handle the touch events yourself. See https://doc.qt.io/qt-5/qscroller.html for more.

      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved