-
最終效果
1.1 父界面 MainWindow即qt建立時自帶的QMainWindow界面
-
代碼分析
2.1 other_page .h(即建立後自動生成的界面,代碼不做修改)
2.2 other_page.cpp 中構造函數class other_page : public QWidget //子界面繼承自QWidget { Q_OBJECT public: explicit other_page(QWidget *parent = );//在類定義時要留下父界面指針 ~other_page(); private: Ui::other_page *ui; };
other_page::other_page(QWidget *parent) : QWidget(parent), ui(new Ui::other_page) { ui->setupUi(this); }
2.3 mainwidow 中添加子界面的類指針
other_page* p_ot;
2.4 mainwindow 構造函數中執行個體化該類(位置不受影響)
2.5 main函數不做任何修改直接運作即可。p_ot = new other_page(this); p_ot->show();