Найти - Пользователи
Полная версия: PyQt текст не отображается как ссылка
Начало » GUI » PyQt текст не отображается как ссылка
1
alexander4
Не могу понять, почему текст не отображается как ссылка?
 from PyQt5 import QtWidgets
class MainWindow(QtWidgets.QMainWindow):
    def link(self, linkStr):
        print(linkStr)
    def __init__(self):
        super(MainWindow, self).__init__()
        self.label = QtWidgets.QLabel('some text\n<a href="http://stackoverflow.com/">Stackoverflow</a>', self)
        self.label.linkActivated.connect(self.link)
app = QtWidgets.QApplication([])
widget = MainWindow()
widget.show()
app.exec_()

Самое интересное, что если написать вот так, то ссылка будет работать
 from PyQt5 import QtWidgets
class MainWindow(QtWidgets.QMainWindow):
    def link(self, linkStr):
        print(linkStr)
    def __init__(self):
        super(MainWindow, self).__init__()
        self.label = QtWidgets.QLabel('some text <a href="http://stackoverflow.com/">Stackoverflow</a>', self)
        self.label.linkActivated.connect(self.link)
app = QtWidgets.QApplication([])
widget = MainWindow()
widget.show()
app.exec_()
vic57
alexander4
'some text\n<a href="http://stackoverflow.com/">Stackoverflow</a>'
html не парсится
 some text<br><a href="http://stackoverflow.com/">Stackoverflow</a>
правильно так
alexander4
vic57
Спасибо, помогло)
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB