Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Searching for strings within a QTextBrowser?
Forum Updated to NodeBB v4.3 + New Features

Searching for strings within a QTextBrowser?

Scheduled Pinned Locked Moved General and Desktop
9 Posts 4 Posters 5.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • O Offline
    O Offline
    odonnemr
    wrote on last edited by
    #1

    Are there any built in functions for this? My end goal is to highlight words within the open page of a help document (which is a QTextBrowser) that the user searches for. I know about the QString find() function, but I'm wondering if there's something similar for QTextBrowser. Thanks in advance

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mlong
      wrote on last edited by
      #2

      QTextBrowser inherits "QTextEdit::find()":http://doc.trolltech.com/4.7/qtextedit.html#find

      Software Engineer
      My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

      1 Reply Last reply
      0
      • O Offline
        O Offline
        odonnemr
        wrote on last edited by
        #3

        Is there a way to highlight every occurrence of the word in the text browser, or maybe a way to scroll through them?

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mlong
          wrote on last edited by
          #4

          Iterating through find() until it returns false will return each instance of the pattern. Then you can highlight or do whatever you need to.

          Software Engineer
          My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

          1 Reply Last reply
          0
          • O Offline
            O Offline
            odonnemr
            wrote on last edited by
            #5

            Wouldn't it just return "true", not the word or location of the word? Is there a way I could make a note of the location in the browser when it returns true?

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mlong
              wrote on last edited by
              #6

              Per the docs, when it finds a match, it sets the cursor to select the location. You could make a copy of the cursor location with QTextEdit::textCursor() every time a location is found.

              Disclaimer, it's been a while since I had to use any of this code, so your mileage may vary.

              Software Engineer
              My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

              1 Reply Last reply
              0
              • O Offline
                O Offline
                odonnemr
                wrote on last edited by
                #7

                Looks good man, thank you

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  amban
                  wrote on last edited by
                  #8

                  Hi,
                  This [http://doc.qt.nokia.com/4.7-snapshot/uitools-textfinder.html] example might help you. I was doing the same stuff sometime back.

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    saidiahd
                    wrote on last edited by
                    #9

                    Hi,
                    also you can use regular expression method :
                    link: http://developer.qt.nokia.com/doc/qt-4.7/qml-regexpvalidator.html

                    bq. Detailed Description

                    This element provides a validator, which counts as valid any string which matches a specified regular expression.

                    "Learn from yesterday, live for today, hope for tomorrow." - Albert Einstein -

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved