[PyQt] html text not displaying in QTextBrowser

sw33tz nyavuz.nm20 at gmail.com
Fri Apr 29 19:16:45 BST 2016


I've written a simple browser program that displays html content in a
QTextBrowser. In that html content I have a hyperlink and I want the
hyperlink to open a different page (displaying the html content received
from the server). So basically after the user types in "server" in the url
box the server sends the client (the browser) some html data and then after
it is displayed in the QTextBrowser the user can then click on the link.
After clicking on the link the client requests another page. The server then
fulfills this request by sending the html data and then the browser should
dislay the html contents again. The problem with my code is that after the
second request the html data is not displayed even though all functions are
working correctly. What could be the problem?

class Browser(QtGui.QMainWindow):
    def __init__(self):
        super(Browser, self).__init__()
        self.ui = uic.loadUi('gui_browser.ui')

        self.csi_thread = Client_Server_Interactive_Thread()
        self.connect(self.csi_thread,
QtCore.SIGNAL("display_html(QString)"), self.display_html)

        self.ui.txt_browser.setOpenExternalLinks(True)
        self.connect(self.ui.txt_browser,
                 QtCore.SIGNAL('anchorClicked(const QUrl &)'),
                 self.anchorClickedHandler)

    def anchorClickedHandler(self):
        self.ui.txt_browser.setSource(QtCore.QUrl("html_file.html"))
        send_msg('link') # sends the server a request

    def display_html(self, data):
        temp_html_file = open('html_file.html', 'w')
        temp_html_file.write(data)
        temp_html_file.close()
        self.ui.txt_browser.setText(data)
        self.parse_document(data)

class Client_Server_Interactive_Thread(QtCore.QThread):
    def __init__(self):
        super().__init__()

    def run(self):
        socket_create()
        while True:
            msg = listen_for_msg()
            self.emit(QtCore.SIGNAL('display_html(QString)'), msg)



--
View this message in context: http://python.6.x6.nabble.com/html-text-not-displaying-in-QTextBrowser-tp5189700.html
Sent from the PyQt mailing list archive at Nabble.com.


More information about the PyQt mailing list