Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
local HTML file display in TextBrowser
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?
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(): ???????????
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
QTextBrowserso 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.
It is not working, Do I need webengine for viewing HTML in textbrowser. Can you guide me with this code
Do I need webengine for viewing HTML in textbrowser.
QTextBrowserwill 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
filenameand where you expect it to be found.