• <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è)簡(jiǎ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 閱讀(2962) 評(píng)論(0)  編輯 收藏 引用 所屬分類: QT編程
             
            久久久久久久91精品免费观看| 久久精品人人做人人爽电影蜜月| 久久精品国产2020| 久久亚洲精品人成综合网| 精品国产福利久久久| 久久午夜福利电影| 亚洲精品无码久久一线| 久久精品无码免费不卡| 午夜欧美精品久久久久久久| 久久99精品久久只有精品| 亚洲中文字幕久久精品无码喷水 | 亚洲人成网站999久久久综合| 久久精品国产日本波多野结衣 | 久久久久精品国产亚洲AV无码| 一本久道久久综合狠狠爱| 精品久久久久久久久久久久久久久| 无码人妻久久一区二区三区| 久久久久综合国产欧美一区二区| 婷婷综合久久中文字幕蜜桃三电影 | 一本色道久久88综合日韩精品 | 久久天天躁狠狠躁夜夜网站 | 国产成人精品久久| 久久久久无码专区亚洲av| 国产精品久久久福利| 久久久久国产精品熟女影院 | 99久久精品影院老鸭窝| 少妇人妻88久久中文字幕| 热99RE久久精品这里都是精品免费 | 日本欧美国产精品第一页久久| 97久久精品人人澡人人爽| 久久电影网一区| 99国产欧美精品久久久蜜芽| 一级女性全黄久久生活片免费 | 2022年国产精品久久久久 | 国产成人精品久久亚洲| 日韩久久无码免费毛片软件| 精品久久人人妻人人做精品| 精品久久久久久无码免费| 久久精品夜色噜噜亚洲A∨| 国产激情久久久久影院小草| 久久精品夜色噜噜亚洲A∨|