• <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編程
             
            久久综合日本熟妇| 老司机国内精品久久久久| 久久免费国产精品| 久久天天躁狠狠躁夜夜avapp| 久久婷婷五月综合97色直播| 久久久久人妻一区精品色| 伊人久久免费视频| 亚洲欧洲中文日韩久久AV乱码| 久久久免费精品re6| 欧美与黑人午夜性猛交久久久| 97精品依人久久久大香线蕉97| 久久九九亚洲精品| 狠狠色丁香久久婷婷综合| 麻豆精品久久精品色综合| 国内精品久久久久影院薰衣草 | 精品综合久久久久久888蜜芽| 一级做a爰片久久毛片16| 国产偷久久久精品专区 | 久久精品国产精品亚洲毛片| 久久午夜综合久久| 久久免费精品一区二区| 久久夜色精品国产网站| 伊人久久无码精品中文字幕| 国产69精品久久久久99尤物| 国产91色综合久久免费| 亚洲午夜久久久久妓女影院| 久久人做人爽一区二区三区| 亚洲美日韩Av中文字幕无码久久久妻妇| 91精品日韩人妻无码久久不卡| 色妞色综合久久夜夜| 亚洲精品乱码久久久久久按摩| 亚洲国产成人精品91久久久| 久久夜色精品国产| 欧美精品一区二区久久| 久久精品亚洲欧美日韩久久| 精品欧美一区二区三区久久久| 91精品国产91久久| 久久精品国产一区二区| 欧洲性大片xxxxx久久久| 欧美亚洲国产精品久久| 久久99热这里只有精品国产|