Помощь - Поиск - Пользователи - Календарь
Полная версия этой страницы: простенький highlighter
Форум на CrossPlatform.RU > Библиотеки > Qt > Qt Общие вопросы
void*
собственно не пойму почему не работает простенький подсветчик:
code
OutputHighlighter.h
#ifndef OUTPUT_HIGHLIGHTER_H_
#define OUTPUT_HIGHLIGHTER_H_
#include <QSyntaxHighlighter>
#include <QRegExp>
#include <QVector>
#include <QTextCharFormat>

class QString;
class QTextDocument;
class OutputHighlighter : public QSyntaxHighlighter {
    Q_OBJECT
    public:
        OutputHighlighter(QTextDocument* parent = 0);
    protected:
        virtual void highlightBlock(const QString& text);
    private:
        struct rule {
            QRegExp pattern;
            QTextCharFormat format;
        };
        QVector<rule> rules;
        
        QTextCharFormat warningFormat;
        QTextCharFormat errorFormat;
};
#endif /* OUTPUT_HIGHLIGHTER */


OutputHighlighter.cpp
#include "OutputHighlighter.h"
#include <QtGui>

OutputHighlighter::OutputHighlighter(QTextDocument* parent) : QSyntaxHighlighter(parent) {
    rule r;
    
    warningFormat.setForeground(Qt::yellow);
    errorFormat.setForeground(Qt::red);
    
    r.pattern = QRegExp("\\bwarning\\b");
    r.format = warningFormat;
    
    rules.append(r);
    
    r.pattern = QRegExp("\\berror\\b");
    r.format = errorFormat;
    
    rules.append(r);
}
void OutputHighlighter::highlightBlock(const QString& text) {
    foreach(rule r, rules) {
        QRegExp exp(r.pattern);
        int index = text.indexOf(text);
        while(index >= 0) {
            int length = exp.matchedLength();
            setFormat(index, length, r.format);
            index = text.indexOf(exp, index + length);
        }
    }
}
trdm
А если отладчиком пройтись?
void*
почему-то не находит исходники :(
Для просмотра полной версии этой страницы, пожалуйста, пройдите по ссылке.
Форум IP.Board © 2001-2024 IPS, Inc.