ImageVerifierCode 换一换
格式:DOCX , 页数:26 ,大小:19.66KB ,
资源ID:9635378      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/9635378.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(基于QT的文本编辑器程序源代码.docx)为本站会员(b****7)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

基于QT的文本编辑器程序源代码.docx

1、基于QT的文本编辑器程序源代码 文本编辑器代码 textedit.proTEMPLATE = appTARGET = texteditCONFIG += qt warn_onHEADERS = textedit.hSOURCES = textedit.cpp main.cppRESOURCES += textedit.qrcbuild_all:!build_pass CONFIG -= build_all CONFIG += release# installtarget.path = $QT_INSTALL_DEMOS/texteditsources.files = $SOURCES $HEA

2、DERS $RESOURCES *.pro *.html *.doc imagessources.path = $QT_INSTALL_DEMOS/texteditINSTALLS += target sources textedit.h#ifndef TEXTEDIT_H#define TEXTEDIT_H#include #include #include QT_FORWARD_DECLARE_CLASS(QAction)QT_FORWARD_DECLARE_CLASS(QComboBox)QT_FORWARD_DECLARE_CLASS(QFontComboBox)QT_FORWARD_

3、DECLARE_CLASS(QTextEdit)QT_FORWARD_DECLARE_CLASS(QTextCharFormat)QT_FORWARD_DECLARE_CLASS(QMenu)class TextEdit : public QMainWindow Q_OBJECTpublic: TextEdit(QWidget *parent = 0);protected: virtual void closeEvent(QCloseEvent *e);private: void setupFileActions(); void setupEditActions(); void setupTe

4、xtActions(); bool load(const QString &f); bool maybeSave(); void setCurrentFileName(const QString &fileName);private slots: void fileNew(); void fileOpen(); bool fileSave(); bool fileSaveAs(); void filePrint(); void filePrintPreview(); void filePrintPdf(); void textBold(); void textUnderline(); void

5、 textItalic(); void textFamily(const QString &f); void textSize(const QString &p); void textStyle(int styleIndex); void textColor(); void textAlign(QAction *a); void currentCharFormatChanged(const QTextCharFormat &format); void cursorPositionChanged(); void clipboardDataChanged(); void about(); void

6、 printPreview(QPrinter *);private: void mergeFormatOnWordOrSelection(const QTextCharFormat &format); void fontChanged(const QFont &f); void colorChanged(const QColor &c); void alignmentChanged(Qt:Alignment a); QAction *actionSave, *actionTextBold, *actionTextUnderline, *actionTextItalic, *actionText

7、Color, *actionAlignLeft, *actionAlignCenter, *actionAlignRight, *actionAlignJustify, *actionUndo, *actionRedo, *actionCut, *actionCopy, *actionPaste; QComboBox *comboStyle; QFontComboBox *comboFont; QComboBox *comboSize; QToolBar *tb; QString fileName; QTextEdit *textEdit;#endif main.cpp#include tex

8、tedit.h#include int main( int argc, char * argv ) Q_INIT_RESOURCE(textedit); QApplication a( argc, argv ); TextEdit mw; mw.resize( 700, 800 ); mw.show(); return a.exec(); textedit.cpp#include textedit.h#include #include #include #include #include #include #include #include #include #include #include

9、 #include #include #include #include #include #include #include #include #include #include #include #include #include #ifdef Q_WS_MACconst QString rsrcPath = :/images/mac;#elseconst QString rsrcPath = :/images/win;#endifTextEdit:TextEdit(QWidget *parent) : QMainWindow(parent) this-setWindowTitle(QSt

10、ring(文本编辑器); QTextCodec:setCodecForCStrings(QTextCodec:codecForName(UTF-8); setupFileActions(); setupEditActions(); setupTextActions(); QMenu *helpMenu = new QMenu(帮助, this); menuBar()-addMenu(helpMenu); helpMenu-addAction(关于, this, SLOT(about(); helpMenu-addAction(关于 &Qt, qApp, SLOT(aboutQt(); text

11、Edit = new QTextEdit(this); connect(textEdit, SIGNAL(currentCharFormatChanged(const QTextCharFormat &), this, SLOT(currentCharFormatChanged(const QTextCharFormat &); connect(textEdit, SIGNAL(cursorPositionChanged(), this, SLOT(cursorPositionChanged(); setCentralWidget(textEdit); textEdit-setFocus();

12、 setCurrentFileName(QString(); fontChanged(textEdit-font(); colorChanged(textEdit-textColor(); alignmentChanged(textEdit-alignment(); connect(textEdit-document(), SIGNAL(modificationChanged(bool), actionSave, SLOT(setEnabled(bool); connect(textEdit-document(), SIGNAL(modificationChanged(bool), this,

13、 SLOT(setWindowModified(bool); connect(textEdit-document(), SIGNAL(undoAvailable(bool), actionUndo, SLOT(setEnabled(bool); connect(textEdit-document(), SIGNAL(redoAvailable(bool), actionRedo, SLOT(setEnabled(bool); setWindowModified(textEdit-document()-isModified(); actionSave-setEnabled(textEdit-do

14、cument()-isModified(); actionUndo-setEnabled(textEdit-document()-isUndoAvailable(); actionRedo-setEnabled(textEdit-document()-isRedoAvailable(); connect(actionUndo, SIGNAL(triggered(), textEdit, SLOT(undo(); connect(actionRedo, SIGNAL(triggered(), textEdit, SLOT(redo(); actionCut-setEnabled(false);

15、actionCopy-setEnabled(false); connect(actionCut, SIGNAL(triggered(), textEdit, SLOT(cut(); connect(actionCopy, SIGNAL(triggered(), textEdit, SLOT(copy(); connect(actionPaste, SIGNAL(triggered(), textEdit, SLOT(paste(); connect(textEdit, SIGNAL(copyAvailable(bool), actionCut, SLOT(setEnabled(bool); c

16、onnect(textEdit, SIGNAL(copyAvailable(bool), actionCopy, SLOT(setEnabled(bool); connect(QApplication:clipboard(), SIGNAL(dataChanged(), this, SLOT(clipboardDataChanged(); QString initialFile = 文本编辑器; const QStringList args = QCoreApplication:arguments(); if (args.count() = 2) initialFile = args.at(1

17、); if (!load(initialFile) fileNew();void TextEdit:closeEvent(QCloseEvent *e) if (maybeSave() e-accept(); else e-ignore();void TextEdit:setupFileActions() QToolBar *tb = new QToolBar(this); tb-setWindowTitle(tr(File Actions); addToolBar(tb); QMenu *menu = new QMenu(&文件, this); menuBar()-addMenu(menu)

18、; QAction *a; a = new QAction(QIcon(rsrcPath + /filenew.png), &新建, this); a-setShortcut(QKeySequence:New); connect(a, SIGNAL(triggered(), this, SLOT(fileNew(); tb-addAction(a); menu-addAction(a); a = new QAction(QIcon(rsrcPath + /fileopen.png), &打开, this); a-setShortcut(QKeySequence:Open); connect(a

19、, SIGNAL(triggered(), this, SLOT(fileOpen(); tb-addAction(a); menu-addAction(a); menu-addSeparator(); actionSave = a = new QAction(QIcon(rsrcPath + /filesave.png), &保存, this); a-setShortcut(QKeySequence:Save); connect(a, SIGNAL(triggered(), this, SLOT(fileSave(); a-setEnabled(false); tb-addAction(a)

20、; menu-addAction(a); a = new QAction(&另存为., this); connect(a, SIGNAL(triggered(), this, SLOT(fileSaveAs(); menu-addAction(a); menu-addSeparator(); a = new QAction(QIcon(rsrcPath + /fileprint.png), &打印, this); a-setShortcut(QKeySequence:Print); connect(a, SIGNAL(triggered(), this, SLOT(filePrint(); t

21、b-addAction(a); menu-addAction(a); a = new QAction(QIcon(rsrcPath + /fileprint.png), &打印预览, this); connect(a, SIGNAL(triggered(), this, SLOT(filePrintPreview(); menu-addAction(a); a = new QAction(QIcon(rsrcPath + /exportpdf.png), &转换为 PDF., this); a-setShortcut(Qt:CTRL + Qt:Key_D); connect(a, SIGNAL

22、(triggered(), this, SLOT(filePrintPdf(); tb-addAction(a); menu-addAction(a); menu-addSeparator(); a = new QAction(&退出, this); a-setShortcut(Qt:CTRL + Qt:Key_Q); connect(a, SIGNAL(triggered(), this, SLOT(close(); menu-addAction(a);void TextEdit:setupEditActions() QToolBar *tb = new QToolBar(this); tb

23、-setWindowTitle(tr(Edit Actions); addToolBar(tb); QMenu *menu = new QMenu(&编辑, this); menuBar()-addMenu(menu); QAction *a; a = actionUndo = new QAction(QIcon(rsrcPath + /editundo.png),&撤销, this); a-setShortcut(QKeySequence:Undo); tb-addAction(a); menu-addAction(a); a = actionRedo = new QAction(QIcon

24、(rsrcPath + /editredo.png), &恢复, this); a-setShortcut(QKeySequence:Redo); tb-addAction(a); menu-addAction(a); menu-addSeparator(); a = actionCut = new QAction(QIcon(rsrcPath + /editcut.png), &剪切, this); a-setShortcut(QKeySequence:Cut); tb-addAction(a); menu-addAction(a); a = actionCopy = new QAction

25、(QIcon(rsrcPath + /editcopy.png), &复制, this); a-setShortcut(QKeySequence:Copy); tb-addAction(a); menu-addAction(a); a = actionPaste = new QAction(QIcon(rsrcPath + /editpaste.png), &粘贴, this); a-setShortcut(QKeySequence:Paste); tb-addAction(a); menu-addAction(a); actionPaste-setEnabled(!QApplication:

26、clipboard()-text().isEmpty();void TextEdit:setupTextActions() QToolBar *tb = new QToolBar(this); tb-setWindowTitle(tr(Format Actions); addToolBar(tb); QMenu *menu = new QMenu(&格式, this); menuBar()-addMenu(menu); actionTextBold = new QAction(QIcon(rsrcPath + /textbold.png), &加粗, this); actionTextBold

27、-setShortcut(Qt:CTRL + Qt:Key_B); QFont bold; bold.setBold(true); actionTextBold-setFont(bold); connect(actionTextBold, SIGNAL(triggered(), this, SLOT(textBold(); tb-addAction(actionTextBold); menu-addAction(actionTextBold); actionTextBold-setCheckable(true); actionTextItalic = new QAction(QIcon(rsr

28、cPath + /textitalic.png), &斜体, this); actionTextItalic-setShortcut(Qt:CTRL + Qt:Key_I); QFont italic; italic.setItalic(true); actionTextItalic-setFont(italic); connect(actionTextItalic, SIGNAL(triggered(), this, SLOT(textItalic(); tb-addAction(actionTextItalic); menu-addAction(actionTextItalic); act

29、ionTextItalic-setCheckable(true); actionTextUnderline = new QAction(QIcon(rsrcPath + /textunder.png), &下划线, this); actionTextUnderline-setShortcut(Qt:CTRL + Qt:Key_U); QFont underline; underline.setUnderline(true); actionTextUnderline-setFont(underline); connect(actionTextUnderline, SIGNAL(triggered(), this, SLOT(textUn

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1