• <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 閱讀(2962) 評論(0)  編輯 收藏 引用 所屬分類: QT編程
             
            久久不射电影网| 久久亚洲AV无码精品色午夜| 国产高潮国产高潮久久久91| 中文精品久久久久人妻不卡| 色诱久久久久综合网ywww| 久久精品国产亚洲av麻豆图片| 无码精品久久一区二区三区| 97久久婷婷五月综合色d啪蜜芽 | 久久国产欧美日韩精品| 国产亚洲精品美女久久久| 蜜桃麻豆www久久| 久久久WWW免费人成精品| 香蕉久久夜色精品国产2020| 狠狠综合久久综合88亚洲| 久久AV高清无码| 中文字幕久久欲求不满| 综合久久一区二区三区 | 婷婷久久综合| 久久精品99久久香蕉国产色戒| 久久午夜羞羞影院免费观看| 久久亚洲精品成人av无码网站| 91超碰碰碰碰久久久久久综合| 色综合久久88色综合天天| 国产成人精品久久二区二区| 久久久这里只有精品加勒比| 亚洲精品tv久久久久| 少妇久久久久久被弄高潮| 国产伊人久久| 伊人久久大香线蕉亚洲五月天| 伊人情人综合成人久久网小说| 久久婷婷五月综合国产尤物app| 亚洲日韩中文无码久久| 久久精品国产亚洲av麻豆小说| 国产精品久久99| 国内精品综合久久久40p| 99久久国产免费福利| 国产成人久久久精品二区三区| 精品永久久福利一区二区| 久久中文字幕人妻熟av女| 日本久久中文字幕| 青青青青久久精品国产h久久精品五福影院1421 |