如何制作超链接以在pyqt中的QTextEdit上启动邮件

how to make hyperlink to launch mail on QTextEdit in pyqt

我想要一个 hyperlink 在 QTextEdit 中启动邮件客户端。我试过了,但是单击 link:

时没有任何反应
self.text_area = QTextEdit()
self.text_area.setReadOnly(True)
self.text_area.setText(u'<p> Jhon Doe <a href='"'mailto:jhon@compay.com'"'>jhon@compay.com</a>  </p>')
self.text_area.setTextInteractionFlags(Qt.LinksAccessibleByMouse)

使用QTextBrowser,它是一个专门的class,提供富文本浏览器继承自QTextEdit的超文本导航,因此它至少具有相同的QTextEdit 能力。

import sys

from PyQt5.QtWidgets import QApplication, QTextBrowser

if __name__ == '__main__':
    app = QApplication(sys.argv)
    text_area = QTextBrowser()
    text_area.setText(u'<p> Jhon Doe <a href='"'mailto:jhon@compay.com'"'>jhon@compay.com</a>  </p>')
    text_area.setOpenExternalLinks(True)
    text_area.show()
    sys.exit(app.exec_())