Qt开源编辑器qsciscintilla的一些用法
首先放一张自己做的软件中的编辑器的效果图

中间红色的框就是放在Qt的tabwidget控件中的qsciscintilla编辑器
先从官网下载qsciscintilla源码,在qtcreater中编译,提取静态库和头文件,将库和Qsci中的头文件添加到自己的项目的pro配置文件中,具体编译方法可参考网上的帖子,这里不再赘述,可以运行之后再看下面的操作
1,一些常规设置,都是通过对应的函数来设置
//设置字体
QFont font("Courier", , QFont::Normal);
ui->textEdit->setFont(font);
ui->textEdit->setMarginsFont(font);
QFontMetrics fontmetrics = QFontMetrics(font);
//设置左侧行号栏宽度等
ui->textEdit->setMarginWidth(, fontmetrics.width(""));
ui->textEdit->setMarginLineNumbers(, true);
ui->textEdit->setBraceMatching(QsciScintilla::SloppyBraceMatch);
ui->textEdit->setTabWidth();
//设置括号等自动补全
ui->textEdit->setAutoIndent(true);
//初始设置c++解析器
ui->textEdit->setLexer(new QsciLexerCPP(this));
//设置自动补全
ui->textEdit->setCaretLineVisible(true);
//设置光标所在行背景色
ui->textEdit->setCaretLineBackgroundColor(Qt::lightGray); // ui->textEdit->setCursorPosition(2,2);
//int markerDefine(MarkerSymbol sym, int markerNumber = -1);
ui->textEdit->SendScintilla(QsciScintilla::SCI_SETCODEPAGE,QsciScintilla::SC_CP_UTF8);//设置编码为UTF-8
//得到光标位置
int line,col;
ui->textEdit->getCursorPosition(&line,&col);
2,通过SendScintilla的参数来设置
最新版编辑器(QScintilla_gpl-2.11.1)好多设置都是通过QsciScintillaBase类中的SendScintilla函数来进行设置的,这个函数有多个重载:
//! Send the Scintilla message \a msg with the optional parameters \a
//! wParam and \a lParam.
long SendScintilla(unsigned int msg, unsigned long wParam = ,
long lParam = ) const; //! \overload
long SendScintilla(unsigned int msg, unsigned long wParam,
void *lParam) const; //! \overload
long SendScintilla(unsigned int msg, uintptr_t wParam,
const char *lParam) const; //! \overload
long SendScintilla(unsigned int msg, const char *lParam) const; //! \overload
long SendScintilla(unsigned int msg, const char *wParam,
const char *lParam) const; //! \overload
long SendScintilla(unsigned int msg, long wParam) const; //! \overload
long SendScintilla(unsigned int msg, int wParam) const; //! \overload
long SendScintilla(unsigned int msg, long cpMin, long cpMax,
char *lpstrText) const; //! \overload
long SendScintilla(unsigned int msg, unsigned long wParam,
const QColor &col) const; //! \overload
long SendScintilla(unsigned int msg, const QColor &col) const; //! \overload
long SendScintilla(unsigned int msg, unsigned long wParam, QPainter *hdc,
const QRect &rc, long cpMin, long cpMax) const; //! \overload
long SendScintilla(unsigned int msg, unsigned long wParam,
const QPixmap &lParam) const; //! \overload
long SendScintilla(unsigned int msg, unsigned long wParam,
const QImage &lParam) const;
在这个类的前面有大量的枚举值,既是这个函数可以用到的参数,

大多数枚举值都有英文注释,可自己查找对应的参数,
这里只介绍我自己用到的几个
//SCI_MARKERGET 参数用来设置标记,默认为圆形标记
int nMask = ui->textEdit->SendScintilla(QsciScintilla::SCI_MARKERGET,linenr-);
//SCI_MARKERSETFORE,SCI_MARKERSETBACK设置标记前景和背景标记
ui->textEdit->SendScintilla(QsciScintilla::SCI_MARKERSETFORE, ,QColor(Qt::red));
ui->textEdit->SendScintilla(QsciScintilla::SCI_MARKERSETBACK, ,QColor(Qt::red));
ui->textEdit->SendScintilla(QsciScintilla::SCI_MARKERADD,linenr-);
效果如图

下面设置下划线标记
ui->textEdit->SendScintilla(QsciScintilla::SCI_STYLESETUNDERLINE,linenr,true);
ui->textEdit->SendScintilla(QsciScintilla::SCI_MARKERDEFINE,0,QsciScintilla::SC_MARK_UNDERLINE)
效果如下

删除所有标记
textEdit->SendScintilla(QsciScintilla::SCI_MARKERDELETEALL);
跳转标记
//跳转到下一个标记
void QsciEditor::gotoNext()//函数写完还未测试,大概是这个作用,可自行测试
{
int line,col;
ui->textEdit->getCursorPosition(&line,&col);
ui->textEdit->SendScintilla(QsciScintilla::SCI_MARKERNEXT,line);
}
//跳转到上一个标记
void QsciEditor::gotoPre()
{
int line,col;
ui->textEdit->getCursorPosition(&line,&col);
ui->textEdit->SendScintilla(QsciScintilla::SCI_MARKERPREVIOUS,line);
}
跳转光标到行line,列index
void QsciEditor::setCursorPosition_p(int line,int index)
{
ui->textEdit->setCursorPosition(line-,index);
ui->textEdit->setCaretLineBackgroundColor(Qt::lightGray);
ui->textEdit->SendScintilla(QsciScintilla::SCI_SETFIRSTVISIBLELINE,line);
}
设置词法分析器
QsciLexer *textLexer;//创建一个词法分析器 //常用以下几种,注意添加对应的头文件
textLexer = new QsciLexerCPP; textLexer = new QsciLexerPython; textLexer = new QsciLexerJava; textLexer = new QsciLexerHTML; textLexer = new QsciLexerCSharp; textLexer = new QsciLexerCSS;
textLexer = new QsciLexerJavaScript;
一些编辑操作函数,看函数名就知道是干嘛的了,手动滑稽
ui->textEdit->undo();
ui->textEdit->redo();
ui->textEdit->copy();
ui->textEdit->cut();
ui->textEdit->paste();
ui->textEdit->findFirst(expr,true,false,true,true);
ui->textEdit->findNext();
ui->textEdit->replace(replaceStr);
常用的信号
//编辑器内容被编辑
textChanged()
//是否可复制,大概是这样copyAvailable(bool)
就说这些,剩下的需要去源代码里面找了
Qt开源编辑器qsciscintilla的一些用法的更多相关文章
- Github开源编辑器Atom
Atom是Github社区开发的一款开源编辑器,很有sublime text特色,相当于开源的sublime text. sublime text用了很长时间了,为什么会重新学习使用另外一款编辑器呢? ...
- QT creator 编辑器快捷键
QT creator 编辑器快捷键 一.快捷键配置方法: 进入“工具->选项->环境->键盘”即可配置快捷键. 二.常用默认快捷键: 编号 快捷键 功能 1 ...
- Github上的一些高分Qt开源项目【多图】
游戏2D地图编辑器: 著名的TileMap编辑器,做2D游戏开发的一定不会陌生. Go 语言的IDE: Go语言的集成开发环境. Clementine Music Player: 功能很完善且跨平台支 ...
- Qt Creator编辑器乱问题
新安装的Qt Creator 打开原来的工程源码时提示:无法用 "UTF-8"-编码解码 "main.cpp". 无法编辑 解决办法:修改项目属性的编辑器设 ...
- Qt探秘——谈ui文件的用法
转载自:点击打开链接http://blog.csdn.net/luo_isaiah/article/details/5794973 相信用过Qt Designer的朋友,对Qt Project中的.u ...
- vs2008编译QT开源项目三国杀(五篇文章)
请参看 http://tieba.baidu.com/f?kz=1508964881 按照上面的网址教程,下载三国杀源码,swig工具,并下载最新的QT4.8.2 for vs2008.我本机已经安装 ...
- Thinkphp编辑器扩展类kindeditor用法
一, 使用前的准备. 使用前请确认你已经建立好了一个Thinkphp站点项目. 1,Keditor.class.php和JSON.class.php 是编辑器扩展类文件,将他们拷贝到你的站点项目的Th ...
- Qt下拉对话框 ComboBox的用法
介绍 ComboBox是Qt的下拉菜单的一个控件,通过下拉菜单选择不同的选项,样式如图: 基本用法 m_ComBox = ui.comboBox; //设置默认显示值的索引,从0开始 m_ComBox ...
- 淘宝开源编辑器Kissy Editor和简易留言编辑器【转】
原来也写过一篇关于百度Ueditor编辑器的介绍:百度Ueditor编辑器的使用,ASP.NET也可上传图片 最开始是使用CuteEditor控件,需要好几mb的空间,因为刚开始学习ASP.NET的时 ...
随机推荐
- Elasticsearch核心技术与实战-简介
讲师阮一鸣介绍ebay的Pronto团队在ebay内部管理上百个Elasticsearch集群,超过4000个数据节点.在生产环境上支持的服务有 订单搜索.商品推荐.日志管理.风险控制.IT运维.安全 ...
- python创建文件夹
import os filePath = 'D:\12345' # 判断文件夹是否存在,不存在则创建文件夹if not os.path.exists(filePath): os.makedirs(fi ...
- 关于xshell连接limux界面按退格键不正常的问题
这个问题通过修改xshell终端属性可以解决,步骤如下: "文件" -> "属性" -> "终端" -> "键盘 ...
- Error 1327 Invalid Drive 的解决办法
出现场景: 当我在安装STM32公司的 STM32 ST-LINK Utility v4.5.0 软件时,弹出了这个错误.弹框的内容大体是说找不到D盘,这里忘记截图了. 我的电脑的硬盘是我另一 ...
- Linuxautofs自动挂载服务
autofs服务程序是一种Linux系统守护进程,当检测到用户试图访问一个尚未挂载的文件系统时,将自动挂载该文件系统.将信息填入/etc/fstab文件后,系统在每次开机时都自动将其挂载,而autof ...
- IDEA debug工具使用
参考:https://www.cnblogs.com/jajian/p/9410844.html
- CSP 2019 游记
Day -32 开坑. 没什么好说的,等个 5 天等初赛(应该叫第一轮认证)挂掉之后就能弃坑了. 今天开始停课,虽然每天只停半天,但是感觉还是特别的舒服~ 然而得等初赛过了才能全天停课-- 没关系,熬 ...
- npm ERR! code ENOLOCAL
Microsoft Windows [版本 ] 版权所有 (c) Microsoft Corporation.保留所有权利. G:\vue>cnpm i vue-router -S 'cnpm' ...
- 《细说PHP》 第四版 样章 第二章 PHP的应用与发展 3
2.3 PHP的开发优势 每种编程语言都有针对的领域,当然相同领域也有多个编程语言可以选择, 所以需要了解每种编程语言的优势和劣势,才能更好地去选择使用,在对的开发领域充分发挥它的优势,编写出最优质 ...
- 【shell脚本】点名器===randomName.sh
随机点名,从name.txt文件中读取名字 [root@VM_0_10_centos shellScript]# cat randowName.sh #!/bin/bash # 随机点名器 # 需提前 ...