PDA

View Full Version : Convert links from plain text?



realdarkman71
5th June 2011, 11:01
Hi all,

is it possible to convert a link (without tags) within a plain text for a label, to click on this link?

Example:


QString plainText="Qt allows you to write advanced applications and UIs (http://qt.nokia.com/...) once, and deploy them across desktop and embedded operating systems without rewriting the source code saving time and development cost."
ui->label->setText(plainText);

In the label I need to click on the link to open it in a browser!

Thx!
Chris

Zlatomir
5th June 2011, 12:25
As far as i know you can't do that, but you can use an HTML code for the link in your string and set the label to open the browser, something like:

QString plainText="Qt Link: ( <a href=\"http://qt.nokia.com\">Qt</a> ) ..."; //see the characters you need to escape with \

QLabel *label = new QLabel();

label->setText(plainText);
label->setTextInteractionFlags(Qt::TextBrowserInteraction );
label->setOpenExternalLinks(true);

realdarkman71
5th June 2011, 13:07
The plain text comes from XML ... unfortunately, without any (html) tags, plain text only!

squidge
5th June 2011, 15:44
It's simple enough to search the plain text for things like http:// however and translate them to hyperlinks.