Qt案例學習-01-mainwindow點擊彈出文本對話框

在這裏插入圖片描述

  • 新建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"
//scroll down untill you see "private:"
MyDialog *mDialog;
  • 打開mainwindow.cpp,添加如下代碼:
#include "mydialog.h"

// add codes in the on_action_WIndow_triggered() function
mDialog = new MyDialog(this);
mDialog->show();
  • 保存,運行
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章