I have created a GUI with PyQt5. Now I would like to add hyperlinks to a QTextBrowser
. Unfortunately, the texts are not clickable but instead displayed as normal text and I have a hard time finding out why.
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QTextBrowser
class MainWindow(QWidget):
def __init__(self):
super().__init__()
self.text_browser = QTextBrowser()
self.text_browser.setOpenExternalLinks(True)
self.text_browser.setReadOnly(True)
self.text_browser.append("<a href=https://google.com/>Google</a>")
self.text_browser.append("<a href=https://github.com/>Github</a>")
layout = QVBoxLayout()
layout.addWidget(self.text_browser)
self.setLayout(layout)
if __name__ == '__main__':
app = QApplication(sys.argv)
window = MainWindow()
window.show()
app.exec_()
GUI without links