scrollArea = new QScrollArea(this);
scrollArea->setObjectName(“scrollAreaMain”);
scrollArea->setWidgetResizable(true);
scrollArea->setStyleSheet(“QScrollArea{border:none;}”);
//设置滚动条不显示,用自定义的滚动条
scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
//滚动条样式
QString qss = QString("QScrollBar:vertical{background:transparent;padding:0px;}"
"QScrollBar::handle:vertical{background:rgba(0,0,0,15%);min-height:120px;border-radius:5px;}"
"QScrollBar::handle:vertical:hover,QScrollBar::handle:vertical:pressed{background:rgba(0,0,0,30%);}"
"QScrollBar::add-page:vertical,QScrollBar::sub-page:vertical{background:none;}"
"QScrollBar::add-line:vertical,QScrollBar::sub-line:vertical{background:none;}");
scrollBar = new QScrollBar(Qt::Vertical, this);
scrollBar->setStyleSheet(qss);
scrollBar->setVisible(false);
connect(scrollArea->verticalScrollBar(), SIGNAL(valueChanged(int)), scrollBar, SLOT(setValue(int)));
connect(scrollBar, SIGNAL(valueChanged(int)), scrollArea->verticalScrollBar(), SLOT(setValue(int)));
connect(scrollArea->verticalScrollBar(), SIGNAL(rangeChanged(int, int)), scrollBar, SLOT(setRange(int, int)));