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

ListView scroll and flick speed



  • Hello,

    Qt 5.15.3, Creator 4.14.2

    This is compiled for android (clang Multi-Abi) and testing on a physical device (Samsung note 10).

    Problem: the scroll speed and flick speed in the example provided is lightening fast.

    Primary Goal: one for one drag speed. while maintaining contact I would like the list to move at the same speed as my finger.

    Secondary Goal: Tailor the flick speed settings based on the length of the list, for example (if we are 100 items from bottom (or top), this speed, if we are 50 items from bottom, different speed, or something along those lines).

    I've checked documentation at:
    https://doc.qt.io/qt-5/qscroller.html
    https://doc.qt.io/qt-5/qscrollerproperties.html

    ...but I'm not able to figure out how to piece those functions together to achieve this. I need some help.

    MainWindow.CPP

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    
    MainWindow::MainWindow(QWidget *parent)
        : QMainWindow(parent)
        , ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
    
        QScreen *screen = QApplication::screens().at(0);
        int Hint = screen->availableSize().height();
    
        int nrows = 500;
    
        QWidget *wgt_search_page = new QWidget(this);
    
        QLabel *lbl_search_page_title = new QLabel(this);
        lbl_search_page_title->setFont(QFont("Courier", Hint*0.012));
        lbl_search_page_title->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
        lbl_search_page_title->setText("Exercise Search Results");
    
        QVBoxLayout *vbx_search_page = new QVBoxLayout(this);
        wgt_search_page->setLayout(vbx_search_page);
    
        QListView *lvw_exercise_search = new QListView();
        QStandardItemModel *model = new QStandardItemModel(nrows, 1, this);
    
        int count = 0;
            do{
                QString name = "Exercise " + QVariant(count).toString();
                QStandardItem *item = new QStandardItem(name);
                model->setItem(count, 0, item);
                count++;
            }while(count<nrows);
    
        lvw_exercise_search->setModel(model);
        QScroller::grabGesture(lvw_exercise_search, QScroller::TouchGesture);
        vbx_search_page->addWidget(lbl_search_page_title);
        vbx_search_page->addWidget(lvw_exercise_search);
    
        setCentralWidget(wgt_search_page);
    
    }
    MainWindow::~MainWindow()
    {
        delete ui;
    }
    
    
    

    MainWindow.h

    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    
    #include <QMainWindow>
    #include <QStandardItemModel>
    #include <QListView>
    #include <QStandardPaths>
    #include <QDebug>
    #include <QtSql/QSqlDatabase>
    #include <QtSql/QSqlQuery>
    #include <QFile>
    #include <QScrollArea>
    #include <QScroller>
    #include <QScreen>
    #include <QVBoxLayout>
    #include <QLabel>
    #include <QScrollerProperties>
    
    
    QT_BEGIN_NAMESPACE
    namespace Ui { class MainWindow; }
    QT_END_NAMESPACE
    
    class MainWindow : public QMainWindow
    {
        Q_OBJECT
    
    public:
        MainWindow(QWidget *parent = nullptr);
        ~MainWindow();
    
    private:
        Ui::MainWindow *ui;
    };
    #endif // MAINWINDOW_H
    
    

    Thanks in advance for the help.