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. Cant insert anchor in QTextEdit. Five years-old bug?
Qt 6.11 is out! See what's new in the release blog

Cant insert anchor in QTextEdit. Five years-old bug?

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 2.0k 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.
  • X Offline
    X Offline
    xintrea
    wrote on last edited by
    #1

    I have object textArea by QTextEdit class. I mouse select word, and click special button. Button action - is append anchor to text (link href in QString refereceUrl):

      // Set link
      QTextCharFormat charFormat;
      charFormat.setAnchorHref(refereceUrl);
    
      // If link not empty
      if(refereceUrl.length()>0)
      {
        charFormat.setAnchor(true);
        textArea->textCursor().mergeCharFormat(charFormat);
      }
      else
      {
        // Else link is empty, and we do remove anchor
        charFormat.setAnchor(false);
        textArea->textCursor().setCharFormat(charFormat);
      }
    

    The anchor for selected text is setted, but text dont underline and blue. Text visible as normal text.

    In HTML source i see:

    Before set anchor:

    <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">This any text.</p>
    

    After set anchor to word "any":

    <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">This <a href="https://link.com">any</a> text.</p>
    

    ... and word "any" view as normal word without underline and blue color.

    But! If get all HTML code from textArea.html, and set it again by textArea.setHtml(), then whord "any" view as underline and blue color. The HTML-code Qt automatic set to:

    <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">This <a href="https://link.ru"><span style=" text-decoration: underline; color:#0000ff;">any</span></a> text.</p>
    

    I have this problem now (Qt 5.4.2), and find this problem in Russian forum at 2010 year:

    http://www.forum.crossplatform.ru/index.php?showtopic=4670&mode=linearplus

    Q: This is bug? If this is not bug, please write, how to set anchor in QTextEdit as underline and blue color.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Sounds like a bug indeed. It looks like there's a rendering (or rather a re-rendering) issue. You should check the bug report system to see if it's something known. If not please consider opening a new report providing a minimal compilable example reproducing this behavior.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • M Offline
        M Offline
        MartinSwede
        wrote on last edited by
        #3

        To remove link...

        qTextCharFormat = self.__qTextEdit.textCursor().charFormat()
        if qTextCharFormat.isAnchor():
           qTextCharFormat.setAnchor(False)
           qTextCharFormat.setFontUnderline(False)
           qTextCharFormat.clearForeground()
           self.__qTextEdit.textCursor().setCharFormat(qTextCharFormat)
        

        ...haven't looked at adding link yet but assuming something inverse of the above.

        Cheers

        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