Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. local HTML file display in TextBrowser
Forum Updated to NodeBB v4.3 + New Features

local HTML file display in TextBrowser

Scheduled Pinned Locked Moved Unsolved Qt for Python
6 Posts 2 Posters 1.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.
  • P Offline
    P Offline
    praneshpk
    wrote on 17 Jun 2021, 08:18 last edited by
    #1

    Hi,
    I am trying to browse an HTML file and display it in a text browser. I am quite confused how to display that. Can anyone help me with this?

    J 1 Reply Last reply 17 Jun 2021, 08:30
    0
    • P praneshpk
      17 Jun 2021, 08:18

      Hi,
      I am trying to browse an HTML file and display it in a text browser. I am quite confused how to display that. Can anyone help me with this?

      J Offline
      J Offline
      JonB
      wrote on 17 Jun 2021, 08:30 last edited by
      #2

      @praneshpk
      Assuming you mean QTextBrowser, you are supposed to use setSource() to your file. What did you try?

      1 Reply Last reply
      1
      • P Offline
        P Offline
        praneshpk
        wrote on 17 Jun 2021, 09:35 last edited by
        #3

        I am using python. I have used the browse button to select the files, but I'm confused about how to use textbrowser. I'm struck at this function.

        def browseSlot( self ):
            options = QtWidgets.QFileDialog.Options()
            options |= QtWidgets.QFileDialog.DontUseNativeDialog
            fileName, _ = QtWidgets.QFileDialog.getOpenFileName(
                            None,
                            "QFileDialog.getOpenFileName()",
                            "",
                            "All files(*);;HTML Files (*.html)",
                            options=options)
            if fileName:
                #self.debugPrint( "setting file name: " + fileName )
                self.model.setFileName( fileName )
                self.refreshAll()
                print(fileName)
            return fileName
        
        def refreshAll( self ):
            self.lineEdit.setText( self.model.getFileName() )
        
        def returnPressedSlot( self ):
            fileName =  self.lineEdit.text()
        
        
        def textbrowser():
            ???????????
        
        J 1 Reply Last reply 17 Jun 2021, 11:30
        0
        • P praneshpk
          17 Jun 2021, 09:35

          I am using python. I have used the browse button to select the files, but I'm confused about how to use textbrowser. I'm struck at this function.

          def browseSlot( self ):
              options = QtWidgets.QFileDialog.Options()
              options |= QtWidgets.QFileDialog.DontUseNativeDialog
              fileName, _ = QtWidgets.QFileDialog.getOpenFileName(
                              None,
                              "QFileDialog.getOpenFileName()",
                              "",
                              "All files(*);;HTML Files (*.html)",
                              options=options)
              if fileName:
                  #self.debugPrint( "setting file name: " + fileName )
                  self.model.setFileName( fileName )
                  self.refreshAll()
                  print(fileName)
              return fileName
          
          def refreshAll( self ):
              self.lineEdit.setText( self.model.getFileName() )
          
          def returnPressedSlot( self ):
              fileName =  self.lineEdit.text()
          
          
          def textbrowser():
              ???????????
          
          J Offline
          J Offline
          JonB
          wrote on 17 Jun 2021, 11:30 last edited by
          #4

          @praneshpk said in local HTML file display in TextBrowser:

          def textbrowser():
          ???????????

          I don't know what you intend such a method to do. I (believe) you have said you want to display the HTML file in a QTextBrowser so you need one of those. And that has a QTextBrowser.setSource() method if you want to point it directly to a file/URL, or QTextBrowser.setHtml() if you want to read the HTML file content yourself.

          1 Reply Last reply
          1
          • P Offline
            P Offline
            praneshpk
            wrote on 18 Jun 2021, 10:35 last edited by
            #5

            @JonB said in local HTML file display in TextBrowser:

            self.QTextBrowser.setSource(filename)
            

            It is not working, Do I need webengine for viewing HTML in textbrowser. Can you guide me with this code

            J 1 Reply Last reply 18 Jun 2021, 10:51
            0
            • P praneshpk
              18 Jun 2021, 10:35

              @JonB said in local HTML file display in TextBrowser:

              self.QTextBrowser.setSource(filename)
              

              It is not working, Do I need webengine for viewing HTML in textbrowser. Can you guide me with this code

              J Offline
              J Offline
              JonB
              wrote on 18 Jun 2021, 10:51 last edited by
              #6

              @praneshpk said in local HTML file display in TextBrowser:

              Do I need webengine for viewing HTML in textbrowser.

              No. QTextBrowser will do it.

              It is not working

              setSource() takes a URL. And has two overloads. You need to read https://doc.qt.io/qt-5/qtextbrowser.html#source-prop and consider what you are passing for filename and where you expect it to be found.

              1 Reply Last reply
              1

              1/6

              17 Jun 2021, 08:18

              • Login

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