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
}
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
}