Important: Please read the Qt Code of Conduct -

Unable to click on hiperlinks in QTextBrowser edited by QTextDocument

  • 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);

    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:

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

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