• <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++高級工程師 Android高級軟件工程師 IT集成工程師 音頻工程師 熟悉c,c++,java,c#,py,js,asp等多種語言 程序猿
            QT中QSyntaxHighlighter主要和QTextEdit配合使用,高亮顯示關(guān)鍵字
            一個簡單的例子如下:
            #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) 評論(0)  編輯 收藏 引用 所屬分類: QT編程
             
            91精品国产综合久久香蕉| 久久婷婷色香五月综合激情| 欧美喷潮久久久XXXXx| 午夜人妻久久久久久久久| 麻豆亚洲AV永久无码精品久久| 久久精品欧美日韩精品| 国产精品激情综合久久| 婷婷国产天堂久久综合五月| 国产精品久久久久国产A级| 精品久久久久久99人妻| 午夜精品久久久久久99热| 亚洲国产精品久久| 亚洲狠狠婷婷综合久久久久| 久久香蕉一级毛片| 亚洲国产另类久久久精品黑人 | 国产午夜精品久久久久九九电影| 国产成人AV综合久久| 无码国产69精品久久久久网站| 精品一久久香蕉国产线看播放| 久久久一本精品99久久精品66| 久久亚洲AV成人无码| 久久亚洲高清观看| 久久只有这里有精品4| 久久强奷乱码老熟女网站| 久久香蕉一级毛片| 久久久久成人精品无码中文字幕 | 久久精品亚洲欧美日韩久久| 久久精品国产99久久久古代| 久久久久亚洲AV综合波多野结衣 | 久久e热在这里只有国产中文精品99| 成人久久免费网站| 亚洲七七久久精品中文国产| 久久久91人妻无码精品蜜桃HD| 色噜噜狠狠先锋影音久久| 狠狠久久亚洲欧美专区| 99久久99这里只有免费费精品| 久久精品免费一区二区| 欧美日韩久久中文字幕| 777午夜精品久久av蜜臀 | 色婷婷综合久久久中文字幕| 欧美精品丝袜久久久中文字幕 |