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的时 ...
随机推荐
- Swoole中内置Http服务器
创建httpServer.php文件,代码如下: <?php // 创建服务对象 $http = new swoole_http_server("10.211.55.17", ...
- Winform中设置ZedGraph鼠标悬浮显示举例最近曲线上的点的坐标值和X轴与Y轴的标题
场景 Winform中设置ZedGraph鼠标双击获取距离最近曲线上的点的坐标值: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/ ...
- js相同的正则多次调用test()返回的值却不同
项目中文件上传需要验证文件的格式,第一次正常,第二次就验证不通过了.在验证的地方console.log()两遍,发现结果不一样 !!! 正则和文件名都没变,但是两次的验证结果不同. this.reg ...
- http请求post,文件导出兼容IE10+
1.post的方法里要加responseType: 'blob'参数,不然下载的excel会乱码 2.使用{type: "application/vnd.ms-excel"}的写法 ...
- 配置linux 防火墙,只有固定IP和端口才能能访问完美解决
//添加开放的端口和固定ip vi /etc/sysconfig/iptables [root@root220156 /]# echo "unset MAILCHECK"> ...
- swift多线程定时器
swift多线程定时器的使用 func countDown(_ timeOut:Int,view: UIView){ var timeout = timeOut let queue:DispatchQ ...
- OC深浅复制
浅复制:指针的复制 深复制:内容的复制 主要有两个关键字 copy 和mutablecopy 对于基本类型 判断深浅方法 1.只要=右边从创建到赋值,至少包含一个NSMutable便会重新生成一个对 ...
- 【Gradle】Android Gradle 高级自定义
Android Gradle 高级自定义 使用共享库 Android的包,如android.app,android.content,android.view,android.widget等,是默认包含 ...
- Java反射04 : 通过Array动态创建和访问Java数组
java.lang.reflect.Array类提供了通过静态方法来动态创建和访问Java数组的操作. 本文转载自:https://blog.csdn.net/hanchao5272/article/ ...
- 【转】java中使用WebSocket
传统的请求,都是从客服端到服务端,表现在web应用上就是,消息都只能由浏览器发起请求,调用客户端的方法. webSocket可以从服务器端推送消息给浏览器. 使用场景: 当客户端发起缴费请求时,由服务 ...