• <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編程
             
            久久久久成人精品无码中文字幕| 奇米综合四色77777久久| 亚洲国产精品一区二区久久| 成人精品一区二区久久久| 久久久网中文字幕| 久久精品国产亚洲av麻豆小说| 99久久人人爽亚洲精品美女 | 久久精品国产乱子伦| 午夜精品久久久久久毛片| 国产精自产拍久久久久久蜜| 狠狠色丁香婷婷久久综合五月| 99久久久精品| 色偷偷久久一区二区三区| 久久亚洲高清综合| 亚洲国产精品久久66| 色综合久久久久综合体桃花网| 色偷偷88欧美精品久久久| 久久夜色精品国产亚洲| 久久av无码专区亚洲av桃花岛| 亚洲国产精品嫩草影院久久| 亚洲国产精品久久66| 狠狠色婷婷综合天天久久丁香 | 观看 国产综合久久久久鬼色 欧美 亚洲 一区二区 | 99久久精品国产综合一区| 日韩精品无码久久久久久| 久久婷婷五月综合色奶水99啪| 99久久精品免费| 国産精品久久久久久久| 91久久精一区二区三区大全| 国产精品99精品久久免费| 久久综合久久自在自线精品自| 亚洲精品无码久久毛片| 久久青青草原精品国产不卡| 久久久久久A亚洲欧洲AV冫| 久久激情五月丁香伊人| 久久精品国产WWW456C0M| 久久嫩草影院免费看夜色| 久久伊人色| 国产精品久久久久免费a∨| 久久人人爽人人爽人人片av麻烦| 狠狠色丁香久久婷婷综合图片 |