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的时 ...
随机推荐
- audio标签以及audio对象
一.audio标签 简单语法 <audio src="音频链接"></audio> 属性 属性 值 描述 autoplay 如果出现该属性,则音频在就绪后马 ...
- JavaScript的概念,引入,基本数据类型
08.05自我总结 JavaScript 一.概念 JavaScript(下文我们会用简称JS来代替)是脚本编程语言,JS语言开发的文件是以.js为后缀,通过在html文件中引入该js文件来控制htm ...
- python的pip工具在windows和ubuntu中遇到的问题
pip问题 windows 描述:pip错误-failed to create process/fatal error in launcher 原因:电脑同时装了python2和python3,并且都 ...
- 上传图片到七牛云(客户端 js sdk)
大体思路 上一篇我们讲了如何通过服务器生成一个upToken,那前端拿到这个token后又该如何操作?在这里我给出一个相当简洁的版本. 首先我们来看一下上传的思路:调用七牛模块的upload方法,生成 ...
- leaflet 实现克里金插值功能(附源码下载)
前言 leaflet 入门开发系列环境知识点了解: leaflet api文档介绍,详细介绍 leaflet 每个类的函数以及属性等等 leaflet 在线例子 leaflet 插件,leaflet ...
- android笔记--Intent和IntentFilter详解
本文转载自:https://www.cnblogs.com/liushengjie/archive/2012/08/30/2663066.html 本文转载自:https://www.cnblogs. ...
- Python 读取照片的信息:拍摄时间、拍摄设备、经纬度等,以及根据经纬度通过百度地图API获取位置
通过第三方库exifread读取照片信息.exifread官网:https://pypi.org/project/ExifRead/ 一.安装exifreadpip install exifread ...
- dd 工具使用; SSD 顺序写性能测试;
dd 工具使用: dd 也是我们经常使用到的磁盘测试工具,Linux服务器装好系统之后,想要知道硬盘的读写是否能满足服务的需要,如果不满足硬盘的IO就是服务的一个瓶颈.我们可以使用dd命令简单进行测试 ...
- Druid-代码段-2-1
所属文章:池化技术(一)Druid是如何管理数据库连接的? 本代码段对应主流程2,具体用来初始化整个连接池: public void init() throws SQLException { if ( ...
- Python进阶小结
目录 一.异常TODO 二.深浅拷贝 2.1 拷贝 2.2 浅拷贝 2.3 深拷贝 三.数据类型内置方法 3.1 数字类型内置方法 3.1.1 整型 3.1.2 浮点型 3.2 字符串类型内置方法 3 ...