我希望超链接在QTextEdit中启动邮件客户端。我尝试了此操作,但是单击链接时没有任何反应:

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,这是一个专门的类,可为富文本浏览器提供继承自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_())

关于python - 如何制作超链接以在pyqt中的QTextEdit上启动邮件,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49741129/

10-13 09:43