Reputation: 3567
Im trying to highlight all the match words on the editor and can't seem to figure out how to properly highlight the text. I can successfully loop through all the found matches but cant seem to find the right call to highlight it. Here is my code:
bool found = true;
while(found)
{
editor->getCursorPosition(&line, &index);
qDebug() << "line: " << line << " index: " << index;
found = editor->findFirst(pattern, use_regular_expression, is_case_sensitive, match_whole_word_only, use_wrap, search_forward);
if(found)
{
int start = editor->positionFromLineIndex(line, index);
int end = editor->positionFromLineIndex(line, index + pattern.length());
qDebug() << "line: " << line << " start: " << start << " end: " << end;
// Attempts to highlight
editor->SendScintilla(QsciScintilla::SCI_INDICGETSTYLE, QsciScintilla::INDIC_BOX);
editor->SendScintilla(QsciScintilla::SCI_INDICSETFORE, 0x007f00);
//child[0]->SendScintilla(QsciScintilla::SCI_INDICATORFILLRANGE, start, end - start);
editor->SendScintilla(QsciScintilla::SCI_INDICATORFILLRANGE, start, end - start);
editor->setIndicatorForegroundColor(QColor(159, 144, 0));
// editor->setColor(QColor(159, 144, 0));**
}
}
my qDebug()'s is showing that its going through each line and finding the matches and the position of the occurance of the word. But code under the comment // Attempts to highlight is where I cant seem to figure out. Any advice?
Upvotes: 2
Views: 958
Reputation: 31
You can try it.
SendScintilla(QsciScintillaBase::SCI_INDICSETSTYLE,0, INDIC_BOX);
QString docText = text();
int end = docText.lastIndexOf(findText);
int cur = -1;
if(end != -1) {
while(cur != end) {
cur = docText.indexOf(findText,cur+1);`
SendScintilla(QsciScintillaBase::SCI_INDICATORFILLRANGE,cur,
findText.length());
}
}
Upvotes: 1