QT里的滚动条操作,
我理解的QScrollArea对象的使用为,把某个widget绑定到该QScrollArea对象,scrol->setWidget(widget);
绑定的widget对象的长宽超过边界时,会有滚动条的效果。
#include <QtGui/QApplication>
#include <QLabel>
#include <QImage>
#include <QScrollArea>
#include <QHBoxLayout>
void ScrollArea_test::Init()
{ root_widget_ = new QWidget(this);setCentralWidget(root_widget_);QVBoxLayout* root_layout = new QVBoxLayout(root_widget_);setLayout(root_layout);QWidget* widget = new QWidget();QVBoxLayout* layout = new QVBoxLayout(widget);setLayout(layout);QPushButton* btn_1 = new QPushButton();btn_1->setText("zhangsan");btn_1->setFixedSize(600, 600);QPushButton* btn_2 = new QPushButton();btn_2->setText("zhangsan");btn_2->setFixedSize(600, 600);layout->addWidget(btn_1);layout->addWidget(btn_2);QScrollArea* scrol = new QScrollArea();scrol->setWidget(widget);scrol->setWidgetResizable(1);scrol->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);scrol->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);root_layout->addWidget(scrol);QPushButton* btn_3 = new QPushButton();btn_3->setText("lisi");btn_3->setFixedSize(100, 100);root_layout->addWidget(btn_3);}
显示效果为: