0

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 hyperlink I generated, but now this option is no longer working. I still can see the <.a href="smth">smth<./a> as a hyperlink (underlined and in different colour), but I cannot access it.

Any ideas how to change this?

My QTextBrowser config:

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);
Cœur
  • 37,241
  • 25
  • 195
  • 267
Szpaqn
  • 545
  • 5
  • 17

1 Answers1

0

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

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

Because QTextBrowser turns it off after the editing of the text.

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 search engines.

Szpaqn
  • 545
  • 5
  • 17