Pergunta

I'm trying to use QTextBrowser from PySide but I'm facing a problem. Whenever I click on an anchor and append plain text to the QTextBrowser after that, the plain text becomes an anchor! Here is my code:

from PySide.QtGui import QTextBrowser, QApplication

import sys

def anchorClickedMethod(url):
    print url.toString()
    logWidget.append("goodbye")

if __name__ == "__main__":
    app = QApplication(sys.argv)
    logWidget=QTextBrowser()
    logWidget.setOpenLinks(False)
    logWidget.setReadOnly(True)
    logWidget.anchorClicked.connect(anchorClickedMethod)
    logWidget.append("<a href = 2>hello</a>")
    logWidget.show()
    sys.exit(app.exec_())

How can I prevent this automatic conversion of plain text into anchors?

Foi útil?

Solução

The append method will insert a new text block that inherits the character format of the previous block.

One way to override this behaviour would be to wrap the text in span tags:

    logWidget.append("<span>goodbye</span>")
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top