• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            Cpper
            C/C++高級(jí)工程師 Android高級(jí)軟件工程師 IT集成工程師 音頻工程師 熟悉c,c++,java,c#,py,js,asp等多種語言 程序猿
            QT中QSyntaxHighlighter主要和QTextEdit配合使用,高亮顯示關(guān)鍵字
            一個(gè)簡單的例子如下:
            #ifndef HIGHLIGHTER_H
            #define HIGHLIGHTER_H
            #include 
            <QSyntaxHighlighter>
            #include 
            <QTextCharFormat>

            QT_BEGIN_NAMESPACE
            class QTextDocument;
            QT_END_NAMESPACE

            class Highlighter : public QSyntaxHighlighter
            {
                Q_OBJECT
            public:
                Highlighter(QTextDocument 
            *parent = 0);
            public slots:
                
            void setTextQueue(const QStringList& textQueue);
            protected:
                
            void highlightBlock(const QString &text);
            private:
                
            struct HighlightingRule
                {
                    QRegExp pattern;
                    QTextCharFormat format;
                };
                QVector
            <HighlightingRule> highlightingRules;
                QTextCharFormat keywordFormat;
            };

            #endif
            .cpp
            #include <QtGui>
            #include 
            "highlighter.h"

            Highlighter::Highlighter(QTextDocument 
            *parent)
                : QSyntaxHighlighter(parent)
            {
                HighlightingRule rule;

                keywordFormat.setForeground(Qt::darkRed);
                keywordFormat.setFontWeight(QFont::Bold);
            }

            void Highlighter::highlightBlock(const QString &text)
            {
                
            foreach(const HighlightingRule &rule,highlightingRules) 
                {
                    QRegExp expression(rule.pattern);
                    
            int index = expression.indexIn(text);
                    
            while(index >= 0
                    {
                        
            int length = expression.matchedLength();
                        setFormat(index,length,rule.format);
                        index 
            = expression.indexIn(text, index + length);
                    }
                }
                setCurrentBlockState(
            0);
            }

            void Highlighter::setTextQueue(const QStringList& textQueue)
            {
                highlightingRules.clear();
                HighlightingRule rule;

                
            const QString tmp("\\b");
                
            foreach(const QString& str,textQueue)
                {   
                    QString pattern(tmp);
                    pattern 
            += str;
                    pattern 
            += tmp;
                    rule.pattern 
            = QRegExp(pattern);
                    rule.format 
            = keywordFormat;
                    highlightingRules.append(rule);
                }
            }
            在這里setTextQueue是傳入高亮顯示的文本列表
            posted on 2012-04-21 22:59 ccsdu2009 閱讀(2954) 評(píng)論(0)  編輯 收藏 引用 所屬分類: QT編程
             
            狠狠狠色丁香婷婷综合久久俺| 很黄很污的网站久久mimi色 | 亚洲香蕉网久久综合影视| 欧美精品九九99久久在观看| 伊人久久大香线蕉综合网站| 久久天堂AV综合合色蜜桃网| 99久久国产综合精品网成人影院| 久久夜色撩人精品国产| 亚洲va久久久噜噜噜久久男同| 国内精品伊人久久久久| 亚洲欧美国产日韩综合久久| 人妻精品久久无码区| 精品无码久久久久久久动漫| 精品国产日韩久久亚洲| 72种姿势欧美久久久久大黄蕉| 久久久久黑人强伦姧人妻| 久久Av无码精品人妻系列| 久久97久久97精品免视看秋霞| 久久久女人与动物群交毛片| 亚洲性久久久影院| 日韩亚洲欧美久久久www综合网| 久久强奷乱码老熟女网站| 久久国产精品99久久久久久老狼 | 亚州日韩精品专区久久久| 国产午夜久久影院| 亚洲AV日韩精品久久久久久| 久久久久国产精品麻豆AR影院| 国内精品人妻无码久久久影院导航| 久久99精品九九九久久婷婷| 国内精品人妻无码久久久影院| 久久久www免费人成精品| 久久无码国产| 日本国产精品久久| 污污内射久久一区二区欧美日韩 | 中文字幕日本人妻久久久免费 | 97精品伊人久久久大香线蕉| 99久久er这里只有精品18| 亚洲精品无码久久千人斩| 亚洲精品国产美女久久久| 伊人久久大香线蕉AV色婷婷色| 亚洲精品无码久久久久久|