首页 > 其他分享 >Qt实现编辑器

Qt实现编辑器

时间:2022-12-16 14:04:55浏览次数:46  
标签:SLOT setEnabled Qt 实现 SIGNAL textEdit 编辑器 bool connect

TextEdit::TextEdit(QWidget *parent)
: QMainWindow(parent)
{
setToolButtonStyle(Qt::ToolButtonFollowStyle);
setupFileActions();
setupEditActions();
setupTextActions();

{
QMenu *helpMenu = new QMenu(tr("Help"), this);
menuBar()->addMenu(helpMenu);
helpMenu->addAction(tr("About"), this, SLOT(about()));
helpMenu->addAction(tr("About &Qt"), qApp, SLOT(aboutQt()));
}

textEdit = new QTextEdit(this);
connect(textEdit, SIGNAL(currentCharFormatChanged(QTextCharFormat)),
this, SLOT(currentCharFormatChanged(QTextCharFormat)));
connect(textEdit, SIGNAL(cursorPositionChanged()),
this, SLOT(cursorPositionChanged()));

setCentralWidget(textEdit);
textEdit->setFocus();
setCurrentFileName(QString());

QFont textFont("Helvetica");
textFont.setStyleHint(QFont::SansSerif);
textEdit->setFont(textFont);
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, 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->document()->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);
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)));
connect(textEdit, SIGNAL(copyAvailable(bool)), actionCopy, SLOT(setEnabled(bool)));

#ifndef QT_NO_CLIPBOARD
connect(QApplication::clipboard(), SIGNAL(dataChanged()), this, SLOT(clipboardDataChanged()));
#endif

QString initialFile = ":/example.html";
const QStringList args = QCoreApplication::arguments();
if (args.count() == 2)
initialFile = args.at(1);

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(tr("&File"), this);
menuBar()->addMenu(menu);

QAction *a;

QIcon newIcon = QIcon::fromTheme("document-new", QIcon(rsrcPath + "/filenew.png"));
a = new QAction( newIcon, tr("&New"), this);
a->setPriority(QAction::LowPriority);
a->setShortcut(QKeySequence::New);
connect(a, SIGNAL(triggered()), this, SLOT(fileNew()));
tb->addAction(a);
menu->addAction(a);

a = new QAction(QIcon::fromTheme("document-open", QIcon(rsrcPath + "/fileopen.png")),
tr("&Open..."), this);
a->setShortcut(QKeySequence::Open);
connect(a, SIGNAL(triggered()), this, SLOT(fileOpen()));
tb->addAction(a);
menu->addAction(a);

menu->addSeparator();

actionSave = a = new QAction(QIcon::fromTheme("document-save", QIcon(rsrcPath + "/filesave.png")),
tr("&Save"), this);
a->setShortcut(QKeySequence::Save);
connect(a, SIGNAL(triggered()), this, SLOT(fileSave()));
a->setEnabled(false);
tb->addAction(a);
menu->addAction(a);

a = new QAction(tr("Save &As..."), this);
a->setPriority(QAction::LowPriority);
connect(a, SIGNAL(triggered()), this, SLOT(fileSaveAs()));
menu->addAction(a);
menu->addSeparator();
}

Qt实现编辑器_文本框

Qt实现编辑器_工具栏_02

标签:SLOT,setEnabled,Qt,实现,SIGNAL,textEdit,编辑器,bool,connect
From: https://blog.51cto.com/u_15515702/5947329

相关文章

  • QT实现绘图器
    #include<QtWidgets>#ifndefQT_NO_PRINTER#include<QPrinter>#include<QPrintDialog>#endif#include"scribblearea.h"ScribbleArea::ScribbleArea(QWidget*parent)......
  • 用pageOffice控件实现 office word文档 强制留痕编辑Word
    OA办公中,业务需要多人编辑word文档,需要强制留痕功能,用来查看文档编辑过程中的具体修改痕迹。怎么实现word文档的强制留痕呢?2实现方法通过pageOffice实现简单的在线打开......
  • 基于Java实现数据脱敏
    用法Jdk版本大于等于1.8maven依赖<dependency><groupId>red.zyc</groupId><artifactId>desensitization</artifactId><version>2.4.6</version></d......
  • 0基础→自动化测试框架实现:java + testng + httpclient + allure
    必备基础java基础配置文件解析(properties)fastjson的使用(处理json字符串、json数组)jsonpath的使用java操作excel(通过POIHttpClient的使用(get、post请求)TestNG用法 自动化测......
  • zookeeper单机模式实现分布式,开发部署测试模式机器有限情况
    ​​ZooKeeper的部署和测试​​一背景zookeeper是一个开源的分布式应用程序协调服务,是ApacheHadoop 的一个子项目。它是一个为分布式应用提供一致性服务的软件,提供的功能......
  • Qt之模拟键盘按下
     相关资料:https://www.ngui.cc/el/814378.html?action=onClick 一、前言最近在做QWT开发的时候碰到一个问题,QwtPlotZoomer提供的放大、缩小操作只支持鼠标事件或键盘......
  • js中map的实现
    JS中map的实现思路分析map是所有数组都可以用的方法,因此我们可以将方法挂在到Array.prototype上去之后所有的数组都可以访问到这个方法map函数,接收一个函数当作参数,并......
  • 原生JS加jQuery实现拖拽和单击上传文件
    单击实现用的是html的input标签,设置multiple='multiple'之后就可以同时选多个文件了<inputtype="file"multiple='multiple'/>拖拽实现依赖event.dataTransfer实现event.da......
  • Qt QTableView样式设置
                 QtQTableView样式设置 显示效果QSS设置 选中设置:​​QTableView::item:selected​​​​{​​​​background:rgb(0,0,100);​​......
  • 刷新页面怎么实现数字滚动?
    刷新页面,显示动态数据。......