简体   繁体   English

Python PyQt5 QTextBrowser超链接失去链接的一部分

[英]Python PyQt5 QTextBrowser hyperlink loses part of link

Hi i have a small problem with hyperlink in QTextBrowser. 嗨,我在QTextBrowser中的超链接有一个小问题。

I create links with this code with ID from json parsing: 我使用json解析中的ID创建带有此代码的链接:

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: 问题是,当我使用它在QTextBrowser中创建超链接时,会创建链接,但它仅包含以下内容:

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

Somehow i loose this part of code "=17452" when i append link to QtextBrowser 当我将链接附加到QtextBrowser时,不知何故我松开了代码“ = 17452”的这一部分

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_())

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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