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 586 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 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())
    
    JonBJ 1 Reply Last reply
    0
    • R radarjonathan

      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())
      
      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on 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

      • Login

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