Qt 使用QScintilla 编辑lua 脚本

需求:

利用QScintilla 编辑lua 脚本

步骤:

1,下载 QScintilla Riverbank Computing | Download

2, 打开 src/qscintilla.pro 文件 编译出 dll库

3,工程中引入这个库

注意debug 模式 必须加载debug 版本编译的库,不然回提示 "QWidget: Must construct a QApplication before a QWidget"

4,使用

复制代码
#include <QApplication>

#include <QMainWindow>
#include <QVBoxLayout>
#include <qsciscintilla.h>
#include <qscilexerlua.h>
#include <qsciapis.h>

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    // 创建窗口和布局
    QMainWindow  window;

    // 创建编辑器控件
    QsciScintilla editor(&window);
    window.setCentralWidget(&editor);
    editor.setMarginWidth(0, 40);
    editor.setIndentationGuides(true);
    editor.setTabWidth(4);
    editor.setUtf8(true);

    QsciLexerLua *textLexer = new QsciLexerLua;
    editor.setLexer(textLexer);

    //设置编码为UTF-8
    QsciAPIs apis(textLexer);
    apis.add(QString("and"));
    apis.add(QString("break"));
    apis.add(QString("do"));
    apis.add(QString("else"));
    apis.add(QString("elseif"));
    apis.add(QString("end"));
    apis.add(QString("false"));
    apis.add(QString("for"));
    apis.add(QString("function"));
    apis.add(QString("if"));
    apis.add(QString("in"));
    apis.add(QString("local"));
    apis.add(QString("nil"));
    apis.add(QString("not"));
    apis.add(QString("or"));
    apis.add(QString("repeat"));
    apis.add(QString("return"));
    apis.add(QString("then"));
    apis.add(QString("true"));
    apis.add(QString("until"));
    apis.add(QString("while"));
    apis.prepare();

    editor.setAutoCompletionSource(QsciScintilla::AcsAll);
    editor.setAutoCompletionCaseSensitivity(true);
    editor.setAutoCompletionThreshold(1);
    editor.SendScintilla(QsciScintilla::SCI_SETCODEPAGE,QsciScintilla::SC_CP_UTF8);
    editor.setCaretLineVisible(true);
    editor.setFolding(QsciScintilla::BoxedFoldStyle);

    // 显示窗口
    window.show();

    return app.exec();
}

5,效果

相关推荐
岁忧1 小时前
macOS配置 GO语言环境
开发语言·macos·golang
朝朝又沐沐2 小时前
算法竞赛阶段二-数据结构(36)数据结构双向链表模拟实现
开发语言·数据结构·c++·算法·链表
魔尔助理顾问3 小时前
系统整理Python的循环语句和常用方法
开发语言·后端·python
Ares-Wang3 小时前
JavaScript》》JS》 Var、Let、Const 大总结
开发语言·前端·javascript
遇见尚硅谷3 小时前
C语言:*p++与p++有何区别
c语言·开发语言·笔记·学习·算法
SkyrimCitadelValinor4 小时前
c#中让图片显示清晰
开发语言·c#
艾莉丝努力练剑4 小时前
【数据结构与算法】数据结构初阶:详解排序(二)——交换排序中的快速排序
c语言·开发语言·数据结构·学习·算法·链表·排序算法
狐小粟同学4 小时前
JavaEE--3.多线程
java·开发语言·java-ee
颜颜yan_4 小时前
Python面向对象编程详解:从零开始掌握类的声明与使用
开发语言·redis·python
李永奉4 小时前
C语言-流程控制语句:for循环语句、while和do…while循环语句;
c语言·开发语言·c++·算法