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. Unable to click on hiperlinks in QTextBrowser edited by QTextDocument
QtWS25 Last Chance

Unable to click on hiperlinks in QTextBrowser edited by QTextDocument

Scheduled Pinned Locked Moved Solved General and Desktop
qtextbrowserqtextcursor
2 Posts 1 Posters 783 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.
  • michalosM Offline
    michalosM Offline
    michalos
    wrote on last edited by michalos
    #1

    Hi,
    I'm working on a messaging app.
    I use a QTextBrowser to display the message, but when it's read I change it a bit using QTextCursor.

    Before I started to edit the text, I could access any hiperlink I generated, but now this option is no longer working. I still can see the <.a href="smth">smth<./a> as a hiperlink (underlined and in different colour), but I cannot access it.

    Any ideas how to change this?

    My QTextBrowse comfig:

    textBrowserReadConversation->setTextInteractionFlags(Qt::TextBrowserInteraction | Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard | Qt::LinksAccessibleByMouse | Qt::LinksAccessibleByKeyboard);
    textBrowserReadConversation->setOpenLinks(false);
    textBrowserReadConversation->setOpenExternalLinks(true);
    textBrowserReadConversation->setAcceptRichText(true);
    textBrowserReadConversation->setReadOnly(false);
    

    I set the QTextCursor like this:

    QTextDocument *document(textBrowserReadConversation->document());
    QTextCursor cursor(document);
    //then I move it to position, delete the previous text and paste the new text:
    cursor.insertHtml(html);
    
    1 Reply Last reply
    0
    • michalosM Offline
      michalosM Offline
      michalos
      wrote on last edited by
      #2

      The solution was to set the text browsers setTextInteractionFlags() to (textInteractionFlags() | Qt::LinksAccessibleByMouse).
      In my case:

          textBrowserReadConversation->setTextInteractionFlags(textBrowserReadConversation->textInteractionFlags() | Qt::LinksAccessibleByMouse | Qt::LinksAccessibleByKeyboard);
      
      

      I found the solution here:

      https://forum.qt.io/topic/70075/qtextbrowser-anchorclicked-not-emitted/2

      But I'll leave the topic, because it was hard for me to find it through google or the search engine on this forum.

      1 Reply Last reply
      1

      • Login

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