ui(new Ui::Dialog)
{
ui->setupUi(this);
resize(800,480);
scroll->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
scroll->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
scroll->setWidget(viewport);
scroll->setWidgetResizable(true);
viewport->setLayout(l);
for(int i = 0; i < 100; i++)
{
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);
}
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
}
Dialog::Dialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog)
{
ui->setupUi(this);
resize(800,480);
QScrollArea *scroll = new QScrollArea(this);
scroll->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
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
}
To copy to clipboard, switch view to plain text mode
Bookmarks