简体   繁体   中英

Python PyQt5 QTextBrowser hyperlink loses part of link

Hi i have a small problem with hyperlink in QTextBrowser.

I create links with this code with ID from json parsing:

ID = data["response"]["recordings"][0]["id"]
aLink = " <a href=http://***/archive/edit?id=%s>%s</a>" % (ID, ID)

print(aLink)

When i print link i get:

<a href=http://***/archive/edit?id=17452>17452</a>

The problem is that when i use this to create hyperlink in QTextBrowser, the link is created but it holds only this:

http://***/archive/edit?id

Somehow i loose this part of code "=17452" when i append link to QtextBrowser

self.textBrowser.append(aLink)

Any ideas?

You have to set the quotes:

<a href='some-url'> some-text</a>
        ^        ^
        |-quotes-|

Example:

import sys

from PyQt5.QtWidgets import *

app = QApplication(sys.argv)
ID = 17452
aLink = " <a href='http://***/archive/edit?id=%s'>%s</a>" % (ID, ID)
w = QTextBrowser()
w.append(aLink)
w.show()

sys.exit(app.exec_())

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM