Why this is not working or any simple alternative to this:
label= QLabel("<b>Name</b>: ABC | <b>Contact</b>: <a style='text-decoration:none;color:black'href='mailto:[email protected]' title='this is a link to email'>[email protected]</a>")
label.setTextFormat(Qt.RichText)
label.setOpenExternalLinks(True)
Everything works fine except the title. How can i show a hover text when this link is hovered
CodePudding user response:
Qt supports only a limited subset of HTML, which doesn't include the 'title' keyword of anchors.
On the other hand, QLabel has the linkHovered
signal, which can be used to show a QToolTip:
titles = {
'mailto:[email protected]': 'this is a link to email'
}
def hover(url):
if url:
QToolTip.showText(QCursor.pos(), titles.get(url, url))
else:
QToolTip.hideText()
label= QLabel("<b>Name</b>: ABC | <b>Contact</b>: <a style='text-decoration:none;color:black'href='mailto:[email protected]'>[email protected]</a>")
label.setTextFormat(Qt.RichText)
label.setOpenExternalLinks(True)
label.linkHovered.connect(hover)