0

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.

UrbKr
  • 621
  • 2
  • 11
  • 27

1 Answers1

1

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.

ekhumoro
  • 115,249
  • 20
  • 229
  • 336
  • The site is telling me not to write thank yous, but seriously, this saves me a much harder alternative. – UrbKr Oct 18 '13 at 22:52