• <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>

            逛奔的蝸牛

            我不聰明,但我會很努力

               ::  :: 新隨筆 ::  ::  :: 管理 ::

            要在QTextEdit中高亮搜索到的字符串, 使用它的QTextDocument和QTextCursor: 


            void TextFinder::on_findButton_clicked() {

                QString searchString = ui_lineEdit->text();

                QTextDocument *document = ui_textEdit->document();


                bool found = false;


                if (isFirstTime == false)

                    document->undo();


                if (searchString == "") {

                    QMessageBox::information(this, tr("Empty Search Field"),

                            "The search field is empty. Please enter a word and click Find.");

                } else {


                    QTextCursor highlightCursor(document);

                    QTextCursor cursor(document);


                    //***************開始***************

                    cursor.beginEditBlock();


                    QTextCharFormat plainFormat(highlightCursor.charFormat());

                    QTextCharFormat colorFormat = plainFormat;

                    colorFormat.setForeground(Qt::red);


                    while (!highlightCursor.isNull() && !highlightCursor.atEnd()) {

                        highlightCursor = document->find(searchString, highlightCursor,

                                QTextDocument::FindWholeWords);


                        if (!highlightCursor.isNull()) {

                            found = true;

                            highlightCursor.movePosition(QTextCursor::WordRight,

                                    QTextCursor::KeepAnchor);

                            highlightCursor.mergeCharFormat(colorFormat);

                        }

                    }


                    cursor.endEditBlock();

                    //***************結束***************

                    

                    isFirstTime = false;


                    if (found == false) {

                        QMessageBox::information(this, tr("Word Not Found"),

                                "Sorry, the word cannot be found.");

                    }

                }

            }

            posted on 2009-05-24 19:36 逛奔的蝸牛 閱讀(4292) 評論(3)  編輯 收藏 引用 所屬分類: Qt自定義Widget

            評論

            # re: QtWidget: TextFinder(高亮搜索到的字符串) 2010-08-16 15:32 lijunsong
            那個 movePosition 是多余的……  回復  更多評論
              

            # re: QtWidget: TextFinder(高亮搜索到的字符串) 2012-05-11 22:19 gaoshixian
            介個哥們是我瓜大的吧  回復  更多評論
              

            # re: QtWidget: TextFinder(高亮搜索到的字符串) 2012-10-16 15:34 毛竹
            如果是在ListView上呢,要怎么標記高亮  回復  更多評論
              

            国产毛片欧美毛片久久久 | 青青热久久综合网伊人| 狠狠色丁香久久婷婷综合五月 | 91亚洲国产成人久久精品网址| 久久99精品九九九久久婷婷| 久久只这里是精品66| 国产一级持黄大片99久久| 久久久久久久久久免免费精品| 色婷婷综合久久久中文字幕| 国产精品永久久久久久久久久| 99久久国产综合精品女同图片| 久久99精品久久久久久齐齐 | 久久久久久国产精品美女| 久久久青草久久久青草| 奇米影视7777久久精品人人爽| 久久夜色精品国产亚洲| 色综合久久中文字幕无码| 一日本道伊人久久综合影| 99久久精品无码一区二区毛片 | 久久精品国产国产精品四凭| 精品无码久久久久国产| 狠狠精品久久久无码中文字幕| 久久久久久A亚洲欧洲AV冫| 久久精品国产亚洲综合色| 久久久国产乱子伦精品作者| 久久强奷乱码老熟女网站| 日韩久久久久中文字幕人妻| 精品熟女少妇aⅴ免费久久| 久久久91精品国产一区二区三区 | 久久久无码一区二区三区| 中文字幕久久精品无码| 亚洲精品乱码久久久久久久久久久久 | 久久精品成人影院| 久久精品国产福利国产琪琪| 久久精品国产一区二区三区| 久久久久噜噜噜亚洲熟女综合| 久久亚洲国产精品123区| 久久亚洲精品无码播放| 久久久国产视频| 欧洲人妻丰满av无码久久不卡| 久久久无码精品亚洲日韩按摩 |