Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED]QLabel used as email address
Qt 6.11 is out! See what's new in the release blog

[SOLVED]QLabel used as email address

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 6.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    GrahamL
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • L Offline
      L Offline
      lgeyer
      wrote on last edited by
      #2

      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>).

      1 Reply Last reply
      0
      • G Offline
        G Offline
        GrahamL
        wrote on last edited by
        #3

        awesome
        thanks

        1 Reply Last reply
        0
        • L Offline
          L Offline
          lgeyer
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved