PDA

View Full Version : Scrolling using QScroller class ..



p3c0
15th August 2013, 09:22
I'm trying to get kinetic scroll on a widget using Qt 5.1's QScroller class but it does not work when i use "TouchGesture" when deployed to device. The "LeftMouseButtonGesture" gesturetype works properly on desktop as well as the android device. I'm unsure whether my code is correct or wrong.

Following is my code:


Dialog::Dialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog)
{
ui->setupUi(this);
resize(800,480);

QScrollArea *scroll = new QScrollArea(this);
scroll->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOf f);
scroll->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff) ;

QWidget *viewport = new QWidget(this);
scroll->setWidget(viewport);
scroll->setWidgetResizable(true);

QVBoxLayout *l = new QVBoxLayout(viewport);
viewport->setLayout(l);

for(int i = 0; i < 100; i++)
{
QLabel *lb = new QLabel();
lb->setText("Label "+QString::number(i));
lb->setStyleSheet("border-radius: 5px;"
"color: #FAFAFA;"
"background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,"
"stop: 0 #a6a6a6, stop: 0.08 #7f7f7f,"
"stop: 0.39999 #717171, stop: 0.4 #626262,"
"stop: 0.9 #4c4c4c, stop: 1 #333333);"
);
l->addWidget(lb);
}

QVBoxLayout *dialog_layout = new QVBoxLayout(this);
dialog_layout->addWidget(scroll); // add scroll to the QDialog's layout
setLayout(dialog_layout);
show();

QScroller::grabGesture(scroll, QScroller::TouchGesture); //Replace TouchGesture with LeftMouseButtonGesture and it works flawlessly
}

karankumar1609
16th August 2013, 11:58
Why you want to write a custom code for kinetic scroll?

You can use FlickCharm (http://labs.trolltech.com/blogs/2008/11/15/flick-list-or-kinetic-scrolling/) for the same.

p3c0
17th August 2013, 06:01
I'm not using custom scroll. Its a new class provided by Qt 5 which enables kinectic scroll on the scroll areas. Previously in Qt 4 i has used FlickCharm for this purpose.
Now since i'm migrating my application to Qt5 i thought of giving it a try.
Well my observation about QScroller is:
1. QScroller works when using the QScroller::LeftMouseButtonGesture on QScrollArea on touch devices and desktop
2. QScroller works using QScroller::LeftMouseButtonGesture and QScroller::TouchGesture on QListViews/treeviews on touch devices and desktop
3. QScroller doesnot work on QScrollArea when QScroller::TouchGesture is used for touch devices.

wysota
19th August 2013, 15:15
I'm trying to get kinetic scroll on a widget using Qt 5.1's QScroller class but it does not work when i use "TouchGesture" when deployed to device.
Does the gesture itself work? Note that it requires multi-touch as opposed to just using the "mouse".

pliniofernando
16th July 2014, 03:38
You are right! It is exactly what I notice. I just used the
QScroller::LeftMouseButtonGesture in my application and it's working for desktop and android. However it isn't smooth but it's other issue.

I'm not using custom scroll. Its a new class provided by Qt 5 which enables kinectic scroll on the scroll areas. Previously in Qt 4 i has used FlickCharm for this purpose.
Now since i'm migrating my application to Qt5 i thought of giving it a try.
Well my observation about QScroller is:
1. QScroller works when using the QScroller::LeftMouseButtonGesture on QScrollArea on touch devices and desktop
2. QScroller works using QScroller::LeftMouseButtonGesture and QScroller::TouchGesture on QListViews/treeviews on touch devices and desktop
3. QScroller doesnot work on QScrollArea when QScroller::TouchGesture is used for touch devices.