Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

[SOLVED]QLabel used as email address



  • Hi
    I can make a QLabel represent a web link, but is there a way of having a label represent an email address and when the link is clicked open the users email client?

    thanks



  • Just prepend your link with <code>mailto:</code>
    @
    QLabel label("<a href='mailto:someone@somewhere.com'>email someone</a>");
    label.setOpenExternalLinks(true);
    label.show();
    @
    Or connect to the linkActivated signal and use QDesktopServices::openUrl().
    @
    QLabel label("<a href='mailto:someone@somewhere.com'>email someone</a>");
    label.connect(&label, &QLabel::linkActivated, [](const QString &link)
    {
    QDesktopServices:openUrl(QUrl(link));
    });
    label.show();
    @
    Be aware that you can specify a <code>subject</code> and <code>body</code> as well (<code>mailto:user@foo.com?subject=Test&body=Just a test</code>).



  • awesome
    thanks



  • You’re welcome.

    Feel free to prepend the title with ‘[Solved] …’ if your question has been solved to indicate that there is a solution inside.


Log in to reply