• <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配合使用,高亮顯示關鍵字
            一個簡單的例子如下:
            #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 閱讀(2941) 評論(0)  編輯 收藏 引用 所屬分類: QT編程
             
            日韩精品国产自在久久现线拍| 久久夜色tv网站| 国内精品久久久久影院日本| 久久91综合国产91久久精品| 国产激情久久久久影院| 欧美成人免费观看久久| 国内精品久久人妻互换| 欧美一区二区久久精品| 久久99国产精品久久99| 少妇熟女久久综合网色欲| 久久精品a亚洲国产v高清不卡| 久久线看观看精品香蕉国产| 久久久久久久波多野结衣高潮| 国产精品无码久久综合| 久久人人爽人人爽人人AV东京热 | 国产成人精品久久免费动漫| 久久综合九色综合欧美就去吻| 色综合色天天久久婷婷基地| 亚洲精品美女久久久久99| 欧美亚洲国产精品久久| 久久九九兔免费精品6| 亚洲人成伊人成综合网久久久 | AV无码久久久久不卡蜜桃| 青春久久| 色噜噜狠狠先锋影音久久| 久久精品国产精品亚洲| 色狠狠久久综合网| 人人狠狠综合久久亚洲婷婷| 精品久久综合1区2区3区激情| 欧美久久一级内射wwwwww.| 一本色综合久久| 青青草原综合久久大伊人精品| 国内精品欧美久久精品| 久久亚洲精品无码AV红樱桃| 99久久99久久精品国产| 97精品国产97久久久久久免费 | 久久精品视频网| 亚洲精品无码久久一线| 色青青草原桃花久久综合| 国产精品禁18久久久夂久 | 久久久久18|