4

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:abc@gmail.com' title='this is a link to email'>abc@gmail.com</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

eyllanesc
  • 235,170
  • 19
  • 170
  • 241

1 Answers1

3

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:abc@gmail.com': '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:abc@gmail.com'>abc@gmail.com</a>")
label.setTextFormat(Qt.RichText)
label.setOpenExternalLinks(True)
label.linkHovered.connect(hover)
musicamante
  • 41,230
  • 6
  • 33
  • 58