Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QtWebEngine
  4. QWebenginePage findText() method
Forum Updated to NodeBB v4.3 + New Features

QWebenginePage findText() method

Scheduled Pinned Locked Moved Unsolved QtWebEngine
2 Posts 2 Posters 650 Views
  • 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.
  • R Offline
    R Offline
    radarjonathan
    wrote on 27 Dec 2020, 10:56 last edited by
    #1

    I have a problem with using findText() of QWebengineView. I want to build a programm, where I can search a HTML Page for specific words, mark them up and extract them by using the selectedText() method of QWebengineview/page. findText() works fine for searching the page and marking up all occurences of the words on the page. The words are found and the callback function shows "TRUE" for the callback "found". But when I call selectedText() the string is always empty, so nothing is selected on the page. Maybe i'm using the callback function wrong? I'm thankfull for every type of help!!

    class App(QWidget):
         def __init__(self):
              '''Initializer of Main App'''
                super(App, self).__init__()
                self.resize(1920, 1080)
                self.view = QtWebEngineWidgets.QWebEngineView(self)
                self.view.resize(1920, 1080)
    
                self.url = QUrl('https://de.wikipedia.org/wiki/Michael_Phelps')
                self.view.load(self.url)
    
                self.button = QPushButton(self)
                self.button.clicked.connect(self.searchPage)
        
                self.button2 = QPushButton(self)
                self.button2.move(40,40)
        
    
      def searchPage(self):
           flags = QWebEnginePage.FindFlags(0)
           self.view.findText("Michael", flags ,self.callback)
    
      def callback(self, found):
          print(found)
          print(self.view.page().selectedText())
    
    J 1 Reply Last reply 27 Dec 2020, 20:46
    0
    • R radarjonathan
      27 Dec 2020, 10:56

      I have a problem with using findText() of QWebengineView. I want to build a programm, where I can search a HTML Page for specific words, mark them up and extract them by using the selectedText() method of QWebengineview/page. findText() works fine for searching the page and marking up all occurences of the words on the page. The words are found and the callback function shows "TRUE" for the callback "found". But when I call selectedText() the string is always empty, so nothing is selected on the page. Maybe i'm using the callback function wrong? I'm thankfull for every type of help!!

      class App(QWidget):
           def __init__(self):
                '''Initializer of Main App'''
                  super(App, self).__init__()
                  self.resize(1920, 1080)
                  self.view = QtWebEngineWidgets.QWebEngineView(self)
                  self.view.resize(1920, 1080)
      
                  self.url = QUrl('https://de.wikipedia.org/wiki/Michael_Phelps')
                  self.view.load(self.url)
      
                  self.button = QPushButton(self)
                  self.button.clicked.connect(self.searchPage)
          
                  self.button2 = QPushButton(self)
                  self.button2.move(40,40)
          
      
        def searchPage(self):
             flags = QWebEnginePage.FindFlags(0)
             self.view.findText("Michael", flags ,self.callback)
      
        def callback(self, found):
            print(found)
            print(self.view.page().selectedText())
      
      J Online
      J Online
      JonB
      wrote on 27 Dec 2020, 20:46 last edited by
      #2

      @radarjonathan said in QWebenginePage findText() method:

      works fine for searching the page and marking up all occurences of the words on the page

      I think that's all it's supposed to do. It does not select any text, only mark it, else anyway if there are multiple occurrences how would it select them all anyway?

      1 Reply Last reply
      0

      1/2

      27 Dec 2020, 10:56

      • Login

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