- 新建mainwindow工程
- 打開mainwindow.ui,點擊編輯頁面的左上角
Type Here
,重命名爲File
,摁enter鍵後,鼠標點擊其所屬的Type Here
,然後重命名爲New WIndow
,摁 enter 鍵後,主界面下方出現了一行新內容
- 右鍵
actionNew_Window
,選擇Go to slot
,這時mainwindow.cpp裏會自動新建一個函數on_action_WIndow_triggered()
,後續會在裏面定義新建的對話框的相關操作。
- 返回edit頁面,在Forms文件夾,右鍵
Add new...
, 依次選擇Qt-Qt Designer Form-
->choose->Dialog without buttons
->next->next…;將自己添加的dialog命名爲MyDialog
;
- 點擊
mydialog.ui
, 添加一個plain text edit
- 打開
mainwindow.h
#include "mydialog.h"
MyDialog *mDialog;
#include "mydialog.h"
mDialog = new MyDialog(this);
mDialog->show();