• <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è)簡單的例子如下:
            #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) 評(píng)論(0)  編輯 收藏 引用 所屬分類: QT編程
             
            久久99精品久久久久久噜噜 | 999久久久免费精品国产| 狠狠色婷婷久久综合频道日韩 | 99久久精品费精品国产一区二区 | 久久久久久久97| 久久精品9988| 人妻无码αv中文字幕久久琪琪布 人妻无码精品久久亚瑟影视 | 久久久久人妻精品一区三寸蜜桃| 日韩中文久久| 国产精品美女久久久| 精品熟女少妇AV免费久久| 日本道色综合久久影院| 麻豆精品久久久久久久99蜜桃| 91精品国产色综合久久| 一级做a爰片久久毛片毛片| 热re99久久精品国产99热| 久久久精品人妻一区二区三区蜜桃| 久久久精品国产Sm最大网站| 久久久久久亚洲AV无码专区| 精品伊人久久大线蕉色首页| 青青草原综合久久大伊人导航| 精品久久一区二区三区| 午夜精品久久久久久中宇| 三级韩国一区久久二区综合| 久久97久久97精品免视看| 久久噜噜电影你懂的| 狠狠88综合久久久久综合网| 亚洲va中文字幕无码久久不卡 | 99精品久久精品| 久久亚洲精品国产精品| 国产aⅴ激情无码久久| 欧美亚洲国产精品久久| 午夜精品久久久久久影视777| 久久精品国产半推半就| 免费国产99久久久香蕉| 国产69精品久久久久777| 久久久久夜夜夜精品国产| 伊人久久免费视频| 国产精品女同一区二区久久| 久久久久国产精品三级网| 亚洲国产精品嫩草影院久久|