• <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編程
             
            久久国产免费观看精品3| 久久精品国产精品亚洲| 国产精品久久久久久久久软件| 久久精品国产一区二区三区| 久久久99精品一区二区| 中文字幕精品久久久久人妻| 99久久精品日本一区二区免费| 国产成人精品久久亚洲高清不卡 国产成人精品久久亚洲高清不卡 国产成人精品久久亚洲 | 久久人做人爽一区二区三区| 亚洲国产精品无码久久久蜜芽| 亚洲精品高清久久| 精品无码久久久久久午夜| 久久亚洲AV永久无码精品| 久久午夜电影网| 人妻少妇久久中文字幕| 亚洲va久久久噜噜噜久久男同| 久久综合丝袜日本网| 无码人妻久久一区二区三区免费丨| 99久久婷婷国产综合精品草原| 蜜臀av性久久久久蜜臀aⅴ| 欧美久久综合九色综合| 久久国产高清一区二区三区| 国产高潮国产高潮久久久91| 亚洲精品无码久久千人斩| 久久综合狠狠综合久久97色| 亚洲伊人久久大香线蕉苏妲己| 久久亚洲私人国产精品vA| 国产69精品久久久久APP下载| 99久久免费只有精品国产| 国产精品一区二区久久不卡| 国产精品99久久久精品无码| 亚洲午夜久久久久久久久电影网| 日本久久中文字幕| 亚洲欧美一级久久精品| 亚洲国产香蕉人人爽成AV片久久 | 国内精品免费久久影院| 亚洲欧美日韩精品久久| 亚洲综合精品香蕉久久网97| 久久青草国产精品一区| 色综合久久综合网观看| 大美女久久久久久j久久|