孤独的猫

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

1.首选创建三个ui窗体,分别为first.ui(ui_first.h),second.ui(ui_second.h),third.ui(ui_third.h)

2.再创建一个包含三个ui的头文件,并新建一个MyWidget类调用这三个窗体,并写入信号槽实现代码

头文件mywidget.h

#ifndef MYWIDGET_H

#define MYWIDGET_H

 

#include <QtGui>

 

#include "ui_first.h"

#include "ui_second.h"

#include "ui_third.h"

 

class MyWidget : public QWidget

{

Q_OBJECT

public:

MyWidget(QWidget *parent=0);

 

public slots:

void slotChild();

 

private:

Ui::First firstUi;

Ui::Second secondUi;

Ui::Third thirdUi;

};

 

#endif

 

mywidget.cpp:

#include "mywidget.h"

 

MyWidget::MyWidget(QWidget *parent)

: QWidget(parent)

{

 

 

QTabWidget *tabWidget = new QTabWidget(this);

 

QWidget *w1 = new QWidget;

firstUi.setupUi(w1);

 

QWidget *w2 = new QWidget;

secondUi.setupUi(w2);

 

tabWidget->addTab(w1,"First");

tabWidget->addTab(w2,"Second");

 

tabWidget->resize(500,500);

 

connect(firstUi.childPushButton,SIGNAL(clicked()),this,SLOT(slotChild()));

connect(secondUi.closePushButton,SIGNAL(clicked()),this,SLOT(close()));

}

 

void MyWidget::slotChild()

{

QDialog *dlg = new QDialog;

thirdUi.setupUi(dlg);

dlg->exec();

}

 

 

主文件main.cpp:

#include "mywidget.h"

int main(int argc,char *argv[])

{

QApplication app(argc,argv);

QFont font("ZYSong18030",12);

app.setFont(font);

w->show();

return app.exec();

}


posted on 2011-04-11 20:15  孤独的猫  阅读(235)  评论(0编辑  收藏  举报