Search code examples
python-3.xpyqthrefpysideqtextbrowser

PySide/PyQt Text in QTextBrowser disappears after clicking on a link in it


I have the following variable appended to 'QTextBrowser'. It does appear as a link, but when I click on it all the text in the 'QTextBrowser' disappears. All the function the 'anchorClicked' signal is connected to does is print something in the shell so that I know that the signal was received.

word = '<a href>' + '<span style="background-color:#C0C0C0">' + word + '</span>' +'</a>'

self.textBrowser.anchorClicked.connect(self.test)

def test(self,argv_1):
    print('!!!')

Solution

  • Probably what's happening is that the text browser is attempting navigate to the href specified in the anchor. But since the href is empty, it just shows a blank page.

    If you want to stop automatic link navigation, try this:

    self.textBrowser.setOpenLinks(False)
    

    (NB: the anchorClicked signal will still be sent when the link is clicked).