首先放一张自己做的软件中的编辑器的效果图

中间红色的框就是放在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的一些用法的更多相关文章

  1. Github开源编辑器Atom

    Atom是Github社区开发的一款开源编辑器,很有sublime text特色,相当于开源的sublime text. sublime text用了很长时间了,为什么会重新学习使用另外一款编辑器呢? ...

  2. QT creator 编辑器快捷键

    QT creator 编辑器快捷键 一.快捷键配置方法:   进入“工具->选项->环境->键盘”即可配置快捷键.     二.常用默认快捷键:       编号 快捷键 功能 1 ...

  3. Github上的一些高分Qt开源项目【多图】

    游戏2D地图编辑器: 著名的TileMap编辑器,做2D游戏开发的一定不会陌生. Go 语言的IDE: Go语言的集成开发环境. Clementine Music Player: 功能很完善且跨平台支 ...

  4. Qt Creator编辑器乱问题

    新安装的Qt Creator 打开原来的工程源码时提示:无法用 "UTF-8"-编码解码 "main.cpp". 无法编辑   解决办法:修改项目属性的编辑器设 ...

  5. Qt探秘——谈ui文件的用法

    转载自:点击打开链接http://blog.csdn.net/luo_isaiah/article/details/5794973 相信用过Qt Designer的朋友,对Qt Project中的.u ...

  6. vs2008编译QT开源项目三国杀(五篇文章)

    请参看 http://tieba.baidu.com/f?kz=1508964881 按照上面的网址教程,下载三国杀源码,swig工具,并下载最新的QT4.8.2 for vs2008.我本机已经安装 ...

  7. Thinkphp编辑器扩展类kindeditor用法

    一, 使用前的准备. 使用前请确认你已经建立好了一个Thinkphp站点项目. 1,Keditor.class.php和JSON.class.php 是编辑器扩展类文件,将他们拷贝到你的站点项目的Th ...

  8. Qt下拉对话框 ComboBox的用法

    介绍 ComboBox是Qt的下拉菜单的一个控件,通过下拉菜单选择不同的选项,样式如图: 基本用法 m_ComBox = ui.comboBox; //设置默认显示值的索引,从0开始 m_ComBox ...

  9. 淘宝开源编辑器Kissy Editor和简易留言编辑器【转】

    原来也写过一篇关于百度Ueditor编辑器的介绍:百度Ueditor编辑器的使用,ASP.NET也可上传图片 最开始是使用CuteEditor控件,需要好几mb的空间,因为刚开始学习ASP.NET的时 ...

随机推荐

  1. golang-基础

    1.go的特点 兼具动态语言的开发效率与C,C++,java的性能安全性 ,内置编译器 2.go的安装 go的sdk下载:  https://studygolang.com/dl go的IDE下载: ...

  2. python高级编程——进程和进程池

    python提供了一个跨平台的多进程支持——multiprocessing模块,其包含Process类来代表一个进程对象 1.Process语法结构:(注: 传参的时候一定使用关键字传参) 2.自定义 ...

  3. MSSQL 字段分组拼接

    方法1:缺点,不去重,不去空:见表1 with t as( select 'A' parent, 'A1' child union all select 'A', 'A1' union all sel ...

  4. coredump配置、产生、分析以及分析示例

    关键词:coredump.core_pattern.coredump_filter等等. 应用程序在运行过程中由于各种异常或者bug导致退出,在满足一定条件下产生一个core文件. 通常core文件包 ...

  5. June 30th, 2019. Week 26th, Sunday

    It's so easy to be careless, it takes courage and courage to care. 不在乎很容易,但在乎却需要很多勇气. Sometimes it w ...

  6. groupid公司名,artifactid模块名,version版本

  7. layUI学习第三日:layUI模块化开发

    layui 定义为「经典模块化」,具备早前 AMD 的影子,又并非受限于 CommonJS 的那些条条框框, BootStrap 的不同在于:layui 糅合了自身对经典模块化的理解. 除了 layu ...

  8. 一站式解决Mac--socket.gaierror: [Errno 8] nodename nor servname provided, or not known

    socket.gaierror: [Errno 8] nodename nor servname provided, or not known 原因:hostname 没有写在/etc/hosts里 ...

  9. Redis高可用集群-哨兵模式(Redis-Sentinel)

     前言 Redis哨兵模式,用现在流行的话可以说就是一个“哨兵机器人”,给“哨兵机器人”进行相应的配置之后,这个"机器人"可以7*24小时工作,它能能够自动帮助你做一些事情,如监控 ...

  10. C语言程序设计100例之(12):Eratosthenes筛法求质数

    例12   Eratosthenes筛法求质数 问题描述 Eratosthenes筛法的基本思想是:把某范围内的自然数从小到大依次排列好.宣布1不是质数,把它去掉:然后从余下的数中取出最小的数,宣布它 ...