[QT]QT教程之实例分析[六]综合布局实例

重点知识已近在代码里注释...
请仔细看代码
本文原创
转载请保留此链接  http://blog.csdn.net/siren0203

 

头文件

header.h

#ifndef HEADER_H #define HEADER_H #include <QDialog> class QStackedspace; class QStackedWidget ; class QSplitter; class QVBoxLayout; class QHBoxLayout; class QGroupBox; class QListWidget; class Content:public QDialog{ Q_OBJECT public: Content(QWidget *parent=0); QListWidget *list; QStackedWidget *stack; QSplitter *splitter; QVBoxLayout *vbox; QHBoxLayout *hbox; QGroupBox *box1; QGroupBox *box2; QGroupBox *box3; }; #endif // HEADER_H

 

实现代码

main.cpp

#include <QApplication> #include <QSplitter> #include <QListWidget> #include <QHBoxLayout> #include <QVBoxLayout> #include <QStackedWidget> #include <QPushButton> #include <QGroupBox> #include <QGridLayout> #include <QButtonGroup> #include "header.h" Content::Content(QWidget *parent):QDialog(parent){ setWindowTitle(tr("基本设置")); list=new QListWidget(this); list->insertItem(0,tr("基本设置")); list->insertItem(1,tr("联系方式")); list->insertItem(2,tr("详细资料")); QPushButton *submit=new QPushButton(tr("提交")); QPushButton *cancle=new QPushButton(tr("取消")); box1=new QGroupBox(this); box2=new QGroupBox(this); box3=new QGroupBox(this); stack=new QStackedWidget(this); stack->addWidget(box1); stack->addWidget(box2); stack->addWidget(box3); splitter=new QSplitter(Qt::Horizontal); splitter->addWidget(list); splitter->addWidget(stack); splitter->setStretchFactor(1,1); QGridLayout *layout=new QGridLayout(this); layout->addWidget(splitter); setLayout(layout); connect(list,SIGNAL(currentRowChanged(int)),stack,SLOT(setCurrentIndex(int))); box1->setTitle("基本设置"); box2->setTitle("联系方式"); box3->setTitle("详细资料"); QHBoxLayout *gl=new QHBoxLayout(this); gl->setAlignment(Qt::AlignBottom); gl->addStretch(1); //固定按钮位置 不让其大小随窗口改变 gl->addWidget(submit); gl->addWidget(cancle); box1->setLayout(gl); } int main(int argc,char ** argv){ QApplication app(argc,argv); QTextCodec::setCodecForTr( QTextCodec::codecForName("gb2312")); Content c; c.show(); return app.exec(); }  

 

 

 

程序演示

[QT]QT教程之实例分析[六]综合布局实例_第1张图片

你可能感兴趣的:(list,header,layout,Class,qt,Signal)