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



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


  • Lifetime Qt Champion

    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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.