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. QLabel doesn't act like a link while it should

QLabel doesn't act like a link while it should

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 1.3k Views
  • 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.
  • rockinJR Offline
    rockinJR Offline
    rockinJ
    wrote on last edited by
    #1

    code like this:

        cTitle = QStringLiteral("<a href=\"\">")+QChar(0x25b6)+title+"</a>";
        eTitle = QStringLiteral("<a href=\"\">")+QChar(0x25bc)+title+"</a>";
        titleLabel = new QLabel(cTitle, this);
        titleLabel->setTextFormat(Qt::RichText);
        titleLabel->setTextInteractionFlags(Qt::LinksAccessibleByKeyboard | Qt::LinksAccessibleByKeyboard);
        titleLabel->setOpenExternalLinks(false);
    

    but the label still looks like plain text and when clicking nothing happened (I have connected the linkActivated signal

    connect(titleLabel, QLabel::linkActivated, this, clicked);
    

    )
    Any help please. Thanks in advance!

    raven-worxR 1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Does connect return true?
      its normally
      Activated(const QString)
      but new syntax hides that info it seems.

      If you do it all in Designer, it will insert extra to color link
      label->setText("<html><head/><body><p><a href="HELLO!"><span style=" text-decoration: underline; color:#0000ff;">TextLabel</span></a></p></body></html>");

      it does work :)
      https://www.dropbox.com/s/tl4to8nr9i3z5fg/mylink.zip?dl=0

      1 Reply Last reply
      2
      • rockinJR rockinJ

        code like this:

            cTitle = QStringLiteral("<a href=\"\">")+QChar(0x25b6)+title+"</a>";
            eTitle = QStringLiteral("<a href=\"\">")+QChar(0x25bc)+title+"</a>";
            titleLabel = new QLabel(cTitle, this);
            titleLabel->setTextFormat(Qt::RichText);
            titleLabel->setTextInteractionFlags(Qt::LinksAccessibleByKeyboard | Qt::LinksAccessibleByKeyboard);
            titleLabel->setOpenExternalLinks(false);
        

        but the label still looks like plain text and when clicking nothing happened (I have connected the linkActivated signal

        connect(titleLabel, QLabel::linkActivated, this, clicked);
        

        )
        Any help please. Thanks in advance!

        raven-worxR Offline
        raven-worxR Offline
        raven-worx
        Moderators
        wrote on last edited by
        #3

        @rockinJ
        you should at least specify a protocol in the url. Then the text will be rendered as link.
        So use

        QStringLiteral("<a href=\"http://\">")
        

        or even

        QStringLiteral("<a href=\"foo://\">")
        

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        rockinJR 1 Reply Last reply
        2
        • rockinJR Offline
          rockinJR Offline
          rockinJ
          wrote on last edited by
          #4

          thank you @mrjj !
          after study your example, I found that it can work even I change to this:

              cTitle = QStringLiteral("<a href=\"c\">")+QChar(0x25b6)+title+"</a>";
              eTitle = QStringLiteral("<a href=\"e\">")+QChar(0x25bc)+title+"</a>";
              titleLabel = new QLabel(cTitle, this);
          //    titleLabel->setTextFormat(Qt::RichText);
          //    titleLabel->setTextInteractionFlags(Qt::LinksAccessibleByKeyboard | Qt::LinksAccessibleByKeyboard);
          //    titleLabel->setOpenExternalLinks(false);
          

          the only thing we need is to put something into the href instead of an empty string.

          1 Reply Last reply
          2
          • raven-worxR raven-worx

            @rockinJ
            you should at least specify a protocol in the url. Then the text will be rendered as link.
            So use

            QStringLiteral("<a href=\"http://\">")
            

            or even

            QStringLiteral("<a href=\"foo://\">")
            
            rockinJR Offline
            rockinJR Offline
            rockinJ
            wrote on last edited by
            #5

            @raven-worx that's right, thank you!

            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