Cpper
C/C++高级工程师 Android高级软件工程师 IT集成工程师 音频工程师 熟悉c,c++,java,c#,py,js,asp等多种语言 程序猿
class scrollTest : public QWidget
{
    Q_OBJECT
public:
    scrollTest(QWidget 
*parent = 0, Qt::WFlags flags = 0);
    
~scrollTest();
private:
    
void createWidget();
    QWidget
* createGroupBox(const QString& title,int n);
};

scrollTest::scrollTest(QWidget
* parent,Qt::WFlags flags):
QWidget(parent,flags)
{
    createWidget();
}

scrollTest::
~scrollTest()
{
}

void scrollTest::createWidget()
{
    resize(
300,360);

    QGridLayout
* gridLayout = new QGridLayout(this);
    QScrollArea
* scrollArea = new QScrollArea(this);
    
//scrollArea->setWidgetResizable(false);
    
//scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
    
    QWidget
* scrollAreaWidgetContents = new QWidget();
    
//scrollAreaWidgetContents->setGeometry(QRect(0, 0, 380, 251));
    scrollArea->setWidget(scrollAreaWidgetContents);

    gridLayout
->addWidget(scrollArea, 0012);

    QSpacerItem
* horizontalSpacer = new QSpacerItem(298,20,QSizePolicy::Expanding,QSizePolicy::Minimum);
    gridLayout
->addItem(horizontalSpacer, 1011);

    QPushButton
* pushButton = new QPushButton(this);
    pushButton
->setText("OK");
    gridLayout
->addWidget(pushButton, 1111);

    QWidget
* content = new QWidget();
    content
->setMinimumHeight(280);
    
//content->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed);
    
    QVBoxLayout
* vlayout = new QVBoxLayout(content);
    
//scrollArea->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    vlayout->addWidget(createGroupBox("box1",3));
    vlayout
->addWidget(createGroupBox("box2",5));
    vlayout
->addStretch(1);

    scrollArea
->setWidget(content);
    
//scrollArea->setFixedHeight(420);
}

QWidget
* scrollTest::createGroupBox(const QString& title,int n)
{
    QGroupBox
* box = new QGroupBox(title);
    QVBoxLayout
* boxlayout = new QVBoxLayout(box);
    
for(int i=0;i<n;i++)
        boxlayout
->addWidget(new QRadioButton(QString("%1").arg(i)));

    
return box;
}
posted on 2014-12-04 13:54 ccsdu2009 阅读(6178) 评论(1)  编辑 收藏 引用 所属分类: QT编程
Comments

只有注册用户登录后才能发表评论。
【推荐】超50万行VC++源码: 大型组态工控、电力仿真CAD与GIS源码库
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理