user1919235
user1919235

Reputation: 520

Hyperlink to web page in QLabel using PySide

I am having troubles displaying a functional hyperlink to a web page in a QLabel using PySide (Python version 3.2.5). Reading the most upvoted answer from this post c++ - Making QLabel behave like a hyperlink - Stack Overflow, I was under the impression that this would work:

from PySide.QtCore import Qt
from PySide.QtGui import QApplication, QLabel

app = QApplication([])
window = QLabel()
window.setText("<a href=\"http://stackoverflow.com/\" />Stack Overflow</a>")
window.setTextFormat(Qt.RichText)
window.setTextInteractionFlags(Qt.TextBrowserInteraction)
window.setOpenExternalLinks(True)
window.show()
app.exec_()

Unfortunately, the text does not show up as a link. Can anyone please point me in the right direction?

Upvotes: 3

Views: 4487

Answers (1)

Bandhit Suksiri
Bandhit Suksiri

Reputation: 3450

Your link are broken, Fix it should be fine;

from PyQt4.QtGui import QApplication, QLabel

myQApplication = QApplication([])
myQLabel = QLabel()
myQLabel.setText('''<a href='http://stackoverflow.com'>stackoverflow</a>''')
myQLabel.setOpenExternalLinks(True)
myQLabel.show()
myQApplication.exec_()

Upvotes: 5

Related Questions