Reputation: 445
I want a hyperlink to launch a mail client in a QTextEdit. I tried this but nothing happens when clicking the link:
self.text_area = QTextEdit()
self.text_area.setReadOnly(True)
self.text_area.setText(u'<p> Jhon Doe <a href='"'mailto:[email protected]'"'>[email protected]</a> </p>')
self.text_area.setTextInteractionFlags(Qt.LinksAccessibleByMouse)
Upvotes: 2
Views: 1674
Reputation: 243897
Use QTextBrowser
, which is a specialized class that provides a rich text browser with hypertext navigation that inherits from QTextEdit
, so it has at least the same QTextEdit
capabilities.
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:[email protected]'"'>[email protected]</a> </p>')
text_area.setOpenExternalLinks(True)
text_area.show()
sys.exit(app.exec_())
Upvotes: 5