Qt實現文本編輯器(自動補全,語法高亮)


下載編譯qscintilla2_qt5.lib

Qscitinlla下載:https://riverbankcomputing.com/software/qscintilla/download
在Qt4Qt5目錄中用QtCreator打開qscintilla.pro文件,分別編譯release與debug版的qscintilla2_qt5.lib與qscintilla2_qt5d.lib

使用

1,把Qt4Qt5目錄中的Qsci目錄拷貝到要使用的工程源碼目錄,我的:app/source/Qsci
2,app.pro添加

INCLUDEPATH += ./source

# release
# LIBS += -L./Lib -lqscintilla2_qt5
# debug
LIBS += -L./Lib -lqscintilla2_qt5d

3,使用

#include "Qsci/qsciscintilla.h"  
#include "Qsci/qscilexerpython.h" 
#include "Qsci/qsciapis.h"  

QsciScintilla* editor = new QsciScintilla;

QsciLexerPython* textLexer = new QsciLexerPython;
editor -> setLexer(textLexer);
editor -> setMarginType(0, QsciScintilla::NumberMargin);
editor -> setMarginLineNumbers(0, true);
editor -> setMarginWidth(0, 30);

QsciAPIs* apis = new QsciAPIs(textLexer);
apis -> add(QString("import"));
apis -> prepare();

editor -> setAutoCompletionSource(QsciScintilla::AcsAll);
editor -> setAutoCompletionCaseSensitivity(true);
editor -> setAutoCompletionThreshold(1);
editor -> SendScintilla(QsciScintilla::SCI_SETCODEPAGE, QsciScintilla::SC_CP_UTF8);

QVBoxLayout* leftLayout = new QVBoxLayout;
leftLayout -> addWidget(editor);

效果:


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM