QT实现文本编辑器

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

一用Qt4实现的文本编辑器

1. 新建,打开,保存文件

2.基本的文本编辑功能(复制,粘贴,剪切等)

3.不同风格

4.改变文字的大小,颜色,字体等

界面如下:

二工程文件

1. /* src.pro*/

TEMPLATE = app

CONFIG += warn_on \

thread \

qt \

qtestlib

TARGET = texteditor

DESTDIR = ../bin

SOURCES += CMainWindow.cpp \

MainWindow.cpp \

CFindDialog.cpp

HEADERS += CFindDialog.h \

CMainWindow.h \

ui_finddialog.h \

ui_MainWindow.h

FORMS += FindDialog.ui \

MainWindow.ui

RESOURCES += MainWindow.qrc

QT += qt3support

2. /*CMainWindow.cpp*/

#include "CMainWindow.h"

#include "CFindDialog.h"

#include

#include

CMainWindow::CMainWindow(QWidget *parent)

: QMainWindow(parent)

{

setupUi(this);

iniStatusBar();

iniConnect();

fontColorAct = new QAction(QPixmap(32, 32), tr("改变字体颜色"), this);

styleToolBar = new QToolBar(this);

styleToolBar->setObjectName(QString::fromUtf8("styleToolBar"));

styleToolBar->setOrientation(Qt::Horizontal);

this->addToolBar(Qt::TopToolBarArea, styleToolBar);

menu_2->addAction(fontColorAct);

styleToolBar->addAction(fontColorAct);

show();

connect(fontColorAct, SIGNAL(triggered()), this, SLOT(changeColor())); }

void CMainWindow::iniConnect()

{

connect(textEdit, SIGNAL(cursorPositionChanged()),

this, SLOT(doCursorChanged()));

connect(textEdit->document(), SIGNAL(contentsChanged()),

this, SLOT(doModified()));

connect(actionAbout, SIGNAL(triggered()), this, SLOT(doAbout()));

connect(actionHelp, SIGNAL(triggered()), this, SLOT(doHelp()));

connect(actionQuit, SIGNAL(triggered()), this, SLOT(doQuit()));

connect(actionOpen, SIGNAL(triggered()), this, SLOT(doOpen()));

connect(actionAll, SIGNAL(triggered()), this, SLOT(doAll()));

connect(actionASave, SIGNAL(triggered()), this, SLOT(doASave()));

connect(actionClose, SIGNAL(triggered()), this, SLOT(doClose()));

connect(actionCopy, SIGNAL(triggered()), this, SLOT(doCopy()));

connect(actionUndo, SIGNAL(triggered()), this, SLOT(doUndo()));

connect(actionRedo, SIGNAL(triggered()), this, SLOT(doRedo()));

connect(actionSave, SIGNAL(triggered()), this, SLOT(doSave()));

connect(actionFind, SIGNAL(triggered()), this, SLOT(doFind()));

connect(actionNew, SIGNAL(triggered()), this, SLOT(do New()));

connect(actionPaste, SIGNAL(triggered()), this, SLOT(doPaste()));

connect(actionCut, SIGNAL(triggered()), this, SLOT(doCut()));

connect(actionWindows, SIGNAL(triggered()), this, SLOT(doWindows()));

connect(actionWindowsXp, SIGNAL(triggered()), this,

SLOT(doWindowsXp()));

connect(actionCDE, SIGNAL(triggered()), this, SLOT(doCDE()));

connect(actionMotif, SIGNAL(triggered()), this, SLOT(doMotif()));

connect(actionPlastique, SIGNAL(triggered()), this, SLOT(doPlastique()));

connect(actionFont, SIGNAL(triggered()), this, SLOT(doFont()));

}

void CMainWindow::changeColor()

{

QColor color =QColorDialog::getColor(fontColor, this);

if(color.isValid()) {

fontColor = color;

updateColor();

}

textEdit->setTextColor(fontColor);

}

void CMainWindow::doModified()

{

相关文档
最新文档