Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QScroller Kinetic scrolling is not smooth

Tags:

android

ios

qt

Kinetic scrolling is very important for developing mobile applications with Qt and I noticed that it’s not smooth on the devices ( tried with android device and iphone ) . It looks a bit choppy, jumping from one position to the next one and following the finger movement with delay. This is visible especially when trying to scroll slow. The other applications in the devices are scrolling a lot smoother especially in iphone.

I made a simple test project with QFrame ( ui->frame ) containing only buttons. The buttons are added to QVBoxLayout. This frame is added to QcrollArea object which reacts to touch events. And this scrollArea is added to QGridLayout. So the scrolling is only in vertical direction.

I have this code in the constructor of my class which is based on QFrame:

ui->frame->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
ui->frame->setMinimumHeight( 1000 );
ui->frame->setMaximumHeight( 1000 );

m_scrollArea    = new QScrollArea();

m_scrollArea->setWidget( ui->frame );
m_scrollArea->setWidgetResizable( true );
m_scrollArea->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
m_scrollArea->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );

m_layout = new QGridLayout();
m_layout->addWidget( m_scrollArea );
m_layout->setContentsMargins( 0, 0, 0, 0 );
setLayout( m_layout );

QScroller::grabGesture( m_scrollArea, QScroller::LeftMouseButtonGesture );

Am I doing something wrong in my code and what can I do to fix this thing. Is someone else experiencing the same thing? I want my application to be looking as native as possible and this choppy scrolling is really not something normal.

If you need more information I will try to provide. I may try to upload my test project somewhere and add some screen capture of the device if needed.

The Qt version that i’m using is 5.1.1 for the android and Qt 5.1.0RC1 self-build for the ios.

I added

QScrollerProperties sp;
sp.setScrollMetric( QScrollerProperties::DragStartDistance,   0.001 );
sp.setScrollMetric( QScrollerProperties::ScrollingCurve, QEasingCurve::Linear );
QScroller* qs   = QScroller::scroller( m_scrollArea );
qs->setScrollerProperties( sp );

The DragStartDistance makes the scrolling more responsive. What other properties can I fine tune to make the scrolling look better? I also noticed that the GUI paintEvent() is not called every time the QEvent::Scroll is received from the QScrollArea which I guess may lead to choppy scrolling. So I added code to repaint the GUI every time I receive QEvent::Scroll and the scrolling looks little smoother but still not perfect in the android device.

What else can I try?

I'll appreciate any help that you can give me. Thanks!

like image 644
Tsweti Avatar asked Oct 10 '13 14:10

Tsweti


1 Answers

The solution for you problem is here: qtcentre.org. Take a look in my post there. My QScroller is working fine now!

Here is the Qt Code in case the link breaks:

Try setting the verticalScrollMode of your view to ScrollPerPixel>

setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
like image 164
plinioandrade Avatar answered Sep 30 '22 15:09

plinioandrade