Frage

In the following code is there anyway for python to tell what the 'word' in the middle of the href tags was when receiving the anchorClicked signal?

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

I tried with the sender() method, but the sender is QTextBrowser, not the string, so that didn't help.

War es hilfreich?

Lösung

When you create the html, put the word in the href attribute:

 html = '<a href="%s"><span>%s</span></a>' % (word, word)

(NB: you may need to html-escape the words in case they include the characters <, >, &, or ").

You can then extract the word from the QUrl sent by anchorClicked:

 word = url.toString()

Alternatively, you could set the href to a key that can be used to look up the word data in a dict.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top