Подробнее
- ВЕРСИЯ QT: 6.9.0 MSVC
Слова, которые нужно выделить, совпадают.
Код выделения в классе MySyntaxHighlighter:
По сути, этот код похоже на официальную демонстрацию Qt.
Код: Выделить всё
void highlightBlock( const QString& text ) override
{
for ( const HighlightingRule& rule : highlightingRules )
{
QRegularExpressionMatchIterator matchIterator = rule.pattern.globalMatch( text );
while ( matchIterator.hasNext( ) )
{
QRegularExpressionMatch match = matchIterator.next( );
setFormat( match.capturedStart( ), match.capturedLength( ), rule.format );
}
}
// Support multi-line comments
highlightMultilineComments( text );
}
Код: Выделить всё
editor = new CodeEditor( currentTheme, editorContiner );
MySyntaxHighlighter* highlighter = new MySyntaxHighlighter( currentTheme, editor->document( ) );
Код: Выделить всё
explicit CodeEditor( theme* cur_theme, QWidget* parent = nullptr )
: QPlainTextEdit( parent )
{
backgroundColor = cur_theme->backgroundColor;
lineNumberAreaTextColor = cur_theme->lineNumberAreaTextColor;
lineNumberAreaColor = cur_theme->lineNumberAreaColor;
currentColor = cur_theme->currentColor;
fontSize = cur_theme->fontSize;
tabSize = cur_theme->tabSize;
lineNumber = new LineNumberArea( parent, lineNumberAreaColor, lineNumberAreaTextColor, this );
connect( this, &CodeEditor::blockCountChanged, this, &CodeEditor::updateLineNumberAreaWidth );
connect( this, &CodeEditor::updateRequest, this, &CodeEditor::updateLineNumberArea );
connect( this, &CodeEditor::cursorPositionChanged, this, &CodeEditor::highlightCurrentLine );
updateLineNumberAreaWidth( 0 );
setFont( QFont( "Courier", fontSize ) );
setTabStopDistance( tabSize * fontMetrics( ).horizontalAdvance( ' ' ) );
connect( this, &QPlainTextEdit::cursorPositionChanged, this, &CodeEditor::highlightCurrentLine );
QPalette p = this->palette( );
p.setColor( QPalette::Active, QPalette::Base, backgroundColor );
p.setColor( QPalette::Inactive, QPalette::Base, backgroundColor );
this->setPalette( p );
highlightCurrentLine( );
}
Я пытался переключить режим переноса строк в поле ввода, но это не дало эффекта.
Подробнее здесь: https://stackoverflow.com/questions/793 ... ph-will-be