Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyQt5 QLabel hyperlink tooltip/hovertext

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

like image 349
Saurabh Rajkumar Avatar asked Sep 18 '25 16:09

Saurabh Rajkumar


1 Answers

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)
like image 126
musicamante Avatar answered Sep 21 '25 07:09

musicamante