文章评分
次,平均分 :
Qt多窗口切换程序
1.ui文件中布局
2.主要程序
main.cpp
1 2 3 4 5 6 7 8 |
#include <QtGui/QApplication> #include "mainwindow.h" int main(int argc, char *argv[]) { QApplication a(argc, argv); MainWindow w; w.show(); return a.exec(); } |
主界面程序:mainwindow.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> #include "dialog1.h" #include "dialog2.h" namespace Ui { class MainWindow; } class MainWindow : public QMainWindow { Q_OBJECT public: explicit MainWindow(QWidget *parent = 0); ~MainWindow(); private slots: void on_pushButton_clicked(); void on_pushButton_2_clicked(); void on_pushButton_3_clicked(); private: Ui::MainWindow *ui; Dialog1 dialog1; Dialog2 dialog2; }; #endif // MAINWINDOW_H |
mainwindow.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
#include "mainwindow.h" #include "ui_mainwindow.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); } MainWindow::~MainWindow() { delete ui; } void MainWindow::on_pushButton_clicked() { this->hide(); dialog1.show(); dialog1.exec(); this->show(); } void MainWindow::on_pushButton_2_clicked() { this->close(); } void MainWindow::on_pushButton_3_clicked() { this->close(); dialog2.show(); dialog2.exec(); this->show(); } |
dialog1.cpp
-
12345678910111213141516<a href="http://wangbaiyuan.cn/wp-content/uploads/2014/12/20120323102433789.jpg"><img class="aligncenter size-full wp-image-1551" src="http://wangbaiyuan.cn/wp-content/uploads/2014/12/20120323102433789.jpg" alt="20120323102433789" width="1024" height="665" /></a>#include "dialog1.h"#include "ui_dialog1.h"Dialog1::Dialog1(QWidget *parent) :QDialog(parent),ui(new Ui::Dialog1){ui->setupUi(this);}Dialog1::~Dialog1(){delete ui;}void Dialog1::on_pushButton_clicked(){this->close();}
dialog2.cpp与Dialog1相似
关键点:
this->close();
dialog2.show();
dialog2.exec();
this->show();
通过等待dialog.exec()消息,判断主界面是否回显。
运行结果:
该文章转自:http://www.2cto.com/kf/201203/124441.html!除特别注明外,本站所有文章均为王柏元的博客原创,转载请注明出处来自https://wangbaiyuan.cn/qt-multi-window-switches.html
暂无评论