• <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上呢,要怎么標記高亮  回復  更多評論
              

            久久中文字幕一区二区| 久久久久亚洲av综合波多野结衣| 久久天天躁夜夜躁狠狠| 久久人做人爽一区二区三区| 久久精品国产久精国产一老狼| 热re99久久精品国99热| 热久久这里只有精品| 久久伊人五月天论坛| 亚洲国产一成人久久精品| 久久无码av三级| 99久久无色码中文字幕人妻| 久久午夜电影网| 97久久婷婷五月综合色d啪蜜芽| 久久国产一区二区| 亚洲色大成网站WWW久久九九| 国产成人精品久久| 久久精品国产第一区二区三区| 久久国产乱子伦精品免费午夜| 性欧美丰满熟妇XXXX性久久久| 国产农村妇女毛片精品久久| 久久精品国产99久久无毒不卡 | 久久综合九色综合网站| 996久久国产精品线观看| 欧美日韩精品久久免费| 国产精品99久久精品爆乳| 人妻丰满AV无码久久不卡| 一本久久综合亚洲鲁鲁五月天| 99久久精品免费| av国内精品久久久久影院| 国内精品综合久久久40p| 久久久久亚洲av毛片大| 精品99久久aaa一级毛片| 久久99国产精品99久久| 国产成年无码久久久久毛片| 日本人妻丰满熟妇久久久久久| 97精品依人久久久大香线蕉97| 欧美精品一区二区久久| 色欲综合久久躁天天躁| 亚洲国产综合久久天堂| 欧美久久久久久| 久久国产劲爆AV内射—百度|