Search code examples
pythonpython-2.7qtpyqtqt4

QTextBrowser won't append link correctly if that link has equals sign inside it


class TextBrowser(QtGui.QTextBrowser):
    def __init__(self, parent=None):
        QtGui.QTextBrowser.__init__(self, parent)
        self.setAcceptRichText(True)
        self.setOpenExternalLinks(True)
        self.insertHtml('<a href=' + 'https://www.google.com/#q=dfsdf'+'>' + 'gg' + '</a>')
        self.append('<a href=' + 'https://www.google.com/#q=dfsdf' + '>' + 'gg' + '</a>')

So anytime I try to append link that has equals sign QTextBrowser will append only part of the link before the sign. https://www.google.com/#q=dfsdf will become https://www.google.com/#q

setHtml()

works correctly but I just want to add clickable link - not to clean the whole area to display link only. Anything I can do about it?


Solution

  • Always make sure html attributes are enclosed in double-quotes, otherwise special characters like = may be parsed wrongly. The html should look like this:

        <a href="https://www.google.com/#q=dfsdf">gg</a>