Unsolved local HTML file display in TextBrowser
-
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? -
@praneshpk
Assuming you meanQTextBrowser
, you are supposed to use setSource() to your file. What did you try? -
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(): ???????????
-
@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 aQTextBrowser.setSource()
method if you want to point it directly to a file/URL, orQTextBrowser.setHtml()
if you want to read the HTML file content yourself. -
@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
-
@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 forfilename
and where you expect it to be found.