• <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編程
             
            亚洲va久久久噜噜噜久久男同| 久久久九九有精品国产| 精品人妻伦一二三区久久| 日本亚洲色大成网站WWW久久| 熟妇人妻久久中文字幕| 亚洲中文字幕无码久久2020| 久久国产精品无码网站| 久久久精品人妻一区二区三区蜜桃| 久久精品无码免费不卡| 综合久久一区二区三区 | 一本色道久久综合亚洲精品| 国产亚洲美女精品久久久2020| 久久国产精品77777| 亚洲国产天堂久久综合| 亚洲va久久久噜噜噜久久| 久久久久亚洲精品无码网址 | 欧美牲交A欧牲交aⅴ久久| 亚洲午夜久久久| 久久国产乱子精品免费女| 精品久久久久久中文字幕人妻最新| 亚洲午夜久久久久久久久电影网 | 久久精品人人槡人妻人人玩AV| 久久中文字幕视频、最近更新| 精品久久久久久久无码 | 国内精品久久久久久久久电影网| 中文字幕日本人妻久久久免费| 精品一久久香蕉国产线看播放| 国产精品久久自在自线观看| 69SEX久久精品国产麻豆| 精品久久人人爽天天玩人人妻| 中文字幕乱码久久午夜| 久久精品亚洲欧美日韩久久| 免费观看成人久久网免费观看| 久久人爽人人爽人人片AV| 蜜桃麻豆WWW久久囤产精品| 一本色道久久88精品综合| 四虎影视久久久免费| 要久久爱在线免费观看| 久久精品国产亚洲一区二区三区| 99久久99久久精品国产片果冻| 亚洲精品tv久久久久|