• <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編程
             
            久久久久中文字幕| 亚洲午夜精品久久久久久app| 精品乱码久久久久久夜夜嗨| 久久久国产乱子伦精品作者 | 99蜜桃臀久久久欧美精品网站 | 18岁日韩内射颜射午夜久久成人| 久久福利青草精品资源站免费| 伊人久久大香线蕉亚洲| 三级韩国一区久久二区综合 | 国产成人综合久久精品尤物| 99久久超碰中文字幕伊人| 久久亚洲精品中文字幕| 亚洲中文字幕久久精品无码APP| 亚洲国产精品综合久久网络| 久久亚洲AV成人无码软件| 国产成人无码精品久久久性色| 久久久久免费看成人影片| 91精品国产综合久久婷婷| 久久精品中文字幕久久| 久久精品亚洲欧美日韩久久| 伊人久久大香线蕉AV一区二区| 中文字幕久久久久人妻| 久久精品一区二区国产| 精品久久久久中文字| 久久天天躁夜夜躁狠狠躁2022| 人妻无码αv中文字幕久久琪琪布| 亚洲国产精品无码久久| 97超级碰碰碰久久久久| 久久久久成人精品无码| 色欲久久久天天天综合网精品| 久久久久久久91精品免费观看 | 国产成人精品久久一区二区三区| 91精品国产乱码久久久久久| 99久久亚洲综合精品网站| 尹人香蕉久久99天天拍| 精品免费tv久久久久久久| 久久亚洲精品无码播放| a级成人毛片久久| 久久受www免费人成_看片中文| 四虎国产永久免费久久| 久久99精品久久久大学生|