Search code examples
pythonpyqtpyqt4qtextbrowser

QTextBrowser html link not clickable


I am trying to add a link to a QTextBrowser and allow it to be clicked. I can get the link to display properly, but when I hover over it the mouse does not change at all (as if it were a URL to click) and you can't click it.

I have setReadOnly and setOpenExternalLinks to True for the QTextBrowser and properly formatted the html url.

self.playlist_txt = QtGui.QTextBrowser()
self.playlist_txt.setReadOnly(False)
self.playlist_txt.setOpenExternalLinks(True)

url_link = "https://google.com/"
html = '<a href="'+url_link+'">'+url_link+'</a>'
print html
self.playlist_txt.setHtml(html)

Output of "html":

<a href="https://google.com">https://google.com</a>

Solution

  • You must make the QTextBrowser be readonly so that the url can be clicked and open the url:

    self.playlist_txt.setReadOnly(False)