資源簡介
使用Qt制作記事本程序,工程可以完整運行。

代碼片段和文件信息
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?“dnotepad.h“
#include?“ui_dnotepad.h“
DNotepad::DNotepad(QWidget?*parent)?:
????QMainWindow(parent)
????ui(new?Ui::DNotepad)
{
????ui->setupUi(this);
????this->setWindowtitle(“Untitle?-?txt“);//為窗口設置標題
????this->setCentralWidget(ui->textEdit);//將textEdit提升為CentralWidget使得textEdit可以隨著windows窗口大小的變化而變化
????//文件菜單
????connect(ui->actionNew_NSIGNAL(triggered())thisSLOT(slotNewFile()));
????connect(ui->actionOpen_OSIGNAL(triggered())thisSLOT(slotOpenFile()));
????connect(ui->actionSave_SSIGNAL(triggered())thisSLOT(slotSaveFile()));
????connect(ui->actionExit_XSIGNAL(triggered())thisSLOT(close()));
????//編輯菜單
????connect(ui->actionUndoSIGNAL(triggered())ui->textEditSLOT(undo()));
????connect(ui->actionRedoSIGNAL(triggered())ui->textEditSLOT(redo()));
????connect(ui->actioncutSIGNAL(triggered())ui->textEditSLOT(cut()));
????connect(ui->actioncopySIGNAL(triggered())ui->textEditSLOT(copy()));
????connect(ui->actionpasteSIGNAL(triggered())ui->textEditSLOT(paste()));
????connect(ui->actionselect_ALLSIGNAL(triggered())ui->textEditSLOT(selectAll()));
????connect(ui->actionDateTimeSIGNAL(triggered())thisSLOT(slotCurrentDataTime()));
????connect(ui->actionFontSIGNAL(triggered())thisSLOT(slotSetFont()));
????connect(ui->actionColorSIGNAL(triggered())thisSLOT(slotSetColor()));
????//幫助菜單
????connect(ui->actionAbout_QtSIGNAL(triggered())qAppSLOT(aboutQt()));
????connect(ui->actionAboutSIGNAL(triggered())thisSLOT(slotAbout()));
}
DNotepad::~DNotepad()
{
????delete?ui;
}
void?DNotepad::closeEvent(QCloseEvent?*event)
{
????//event->accept();//默認的情況是接受的
????//event->ignore();
????if(ui->textEdit->document()->isModified())
????{
????????QMessageBox?msgBox;
????????msgBox.setText(“文件已經變更!“);
????????msgBox.setInformativeText(“你是否需要保存?“);
????????msgBox.setStandardButtons(QMessageBox::Save?|?QMessageBox::Discard?|?QMessageBox::Cancel);
????????msgBox.setDefaultButton(QMessageBox::Save);
????????int?ret?=?msgBox.exec();//由于QMessageBox繼承與QDialog所以msgBox可以調用dialog的exec()方法
????????switch?(ret)?{
??????????case?QMessageBox::Save:
????????????this->slotSaveFile();
????????????break;
??????????case?QMessageBox::Discard:
????????????this->close();
????????????break;
??????????case?QMessageBox::Cancel:
????????????event->ignore();
????????????break;
??????????default:
??????????????break;
????????}
????}else
????{
????????event->accept();
????}
}
void?DNotepad::slotNewFile()
{
????/*?在這個ui界面文件中,textEdit只是提供了用戶輸入的一個部件,而用戶真正輸入的內容則是
?????*?textEdit中的document所以textEdit中有沒有變化,都是通過document來觀察的變化的實質
?????*?與textEdit沒有關系,而是document在變化。
?????*?*?*?*?*?*/
????//測試當前文檔中的內容是否改變
????if(ui->textEdit->document()
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2016-01-19?00:25??MyNotepad\
?????文件?????????430??2015-08-20?20:09??MyNotepad\MyNotepad.pro
?????文件???????18322??2016-01-19?00:25??MyNotepad\MyNotepad.pro.user
?????文件???????18315??2015-09-23?20:49??MyNotepad\MyNotepad.pro.user.688a49a
?????文件????????1150??2013-07-22?16:20??MyNotepad\app.ico
?????文件????????7218??2015-08-20?22:04??MyNotepad\dnotepad.cpp
?????文件?????????807??2015-08-20?21:46??MyNotepad\dnotepad.h
?????文件????????8032??2015-08-20?22:02??MyNotepad\dnotepad.ui
?????文件???????25214??2013-07-22?16:20??MyNotepad\documents.ico
?????文件?????????656??2015-08-23?16:59??MyNotepad\icon.qrc
?????目錄???????????0??2015-08-20?19:52??MyNotepad\icons\
?????文件???????16858??2015-01-29?15:28??MyNotepad\icons\1.jpg
?????文件??????290871??2015-08-11?18:11??MyNotepad\icons\2.jpg
?????文件???????85362??2015-08-11?18:03??MyNotepad\icons\3.jpg
?????文件????????1760??2010-03-18?17:01??MyNotepad\icons\application-exit.png
?????文件????????1410??2010-03-18?17:01??MyNotepad\icons\document-new.png
?????文件????????1088??2010-03-18?17:01??MyNotepad\icons\document-open.png
?????文件????????2152??2010-03-18?17:01??MyNotepad\icons\document-save-as.png
?????文件????????1263??2010-03-18?17:01??MyNotepad\icons\document-save.png
?????文件?????????860??2010-03-18?17:01??MyNotepad\icons\edit-copy.png
?????文件?????????892??2010-03-18?17:01??MyNotepad\icons\edit-cut.png
?????文件?????????937??2010-03-18?17:01??MyNotepad\icons\edit-paste.png
?????文件????????1998??2010-03-18?17:01??MyNotepad\icons\edit-redo.png
?????文件????????2020??2010-03-18?17:01??MyNotepad\icons\edit-undo.png
?????文件?????????621??2015-08-23?17:10??MyNotepad\main.cpp
?????文件??????????57??2015-08-20?20:13??MyNotepad\myapp.rc
?????文件??????922205??2015-06-18?20:56??MyNotepad\screen.jpg
?????文件??????226673??2014-05-21?17:17??MyNotepad\screen.png
評論
共有 條評論