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