• <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 逛奔的蝸牛 閱讀(4303) 評論(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上呢,要怎么標記高亮  回復  更多評論
              

            久久精品国产亚洲AV忘忧草18 | 久久精品成人免费看| 蜜桃麻豆WWW久久囤产精品| 尹人香蕉久久99天天拍| 99精品国产综合久久久久五月天| 亚洲国产精品成人久久| 国产V亚洲V天堂无码久久久| 免费观看成人久久网免费观看| 久久精品国产色蜜蜜麻豆| 久久天天躁狠狠躁夜夜2020一 | 久久精品国产免费一区| 综合久久精品色| 日本福利片国产午夜久久| 精品熟女少妇AV免费久久| 久久久久久久99精品免费观看| 伊人久久大香线蕉综合热线| 国产精品xxxx国产喷水亚洲国产精品无码久久一区 | 久久亚洲中文字幕精品一区四| 国产精品伦理久久久久久| 久久国语露脸国产精品电影| 国产精品女同久久久久电影院| 久久伊人五月天论坛| 久久精品99久久香蕉国产色戒| 久久久久久国产精品无码下载 | 久久国产成人| 色综合久久无码中文字幕| 亚洲∧v久久久无码精品| 亚洲精品NV久久久久久久久久| 久久亚洲欧美国产精品| 色综合久久天天综线观看| 久久久久噜噜噜亚洲熟女综合 | 国产高潮久久免费观看| 2021国产成人精品久久| 精品久久久久久久| 久久精品国产精品亚洲人人| 亚洲乱亚洲乱淫久久| 久久亚洲精品国产亚洲老地址| 蜜桃麻豆www久久国产精品| 久久综合亚洲色一区二区三区| 伊人久久大香线焦AV综合影院| 99久久无码一区人妻a黑|