Results 1 to 4 of 4

Thread: Convert links from plain text?

  1. #1
    Join Date
    Oct 2010
    Location
    Earth
    Posts
    50
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    3

    Default Convert links from plain text?

    Hi all,

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

    Example:

    Qt Code:
    1. 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."
    2. ui->label->setText(plainText);
    To copy to clipboard, switch view to plain text mode 

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

    Thx!
    Chris

  2. #2
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android
    Thanks
    62
    Thanked 260 Times in 246 Posts

    Default Re: Convert links from plain text?

    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:
    Qt Code:
    1. QString plainText="Qt Link: ( <a href=\"http://qt.nokia.com\">Qt</a> ) ..."; //see the characters you need to escape with \
    2.  
    3. QLabel *label = new QLabel();
    4.  
    5. label->setText(plainText);
    6. label->setTextInteractionFlags(Qt::TextBrowserInteraction);
    7. label->setOpenExternalLinks(true);
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Oct 2010
    Location
    Earth
    Posts
    50
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    3

    Default Re: Convert links from plain text?

    The plain text comes from XML ... unfortunately, without any (html) tags, plain text only!

  4. #4
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    6
    Thanked 348 Times in 333 Posts

    Default Re: Convert links from plain text?

    It's simple enough to search the plain text for things like http:// however and translate them to hyperlinks.

Similar Threads

  1. How to convert image data type to plain text and back ?
    By aircraftstories in forum Qt Programming
    Replies: 3
    Last Post: 13th April 2011, 17:00
  2. Convert html links in widget actions
    By jiveaxe in forum Qt Programming
    Replies: 4
    Last Post: 16th November 2009, 13:17
  3. About Box - Scroll Plain Text
    By sheeeng in forum Newbie
    Replies: 2
    Last Post: 20th October 2009, 10:04
  4. QString is a richText or plain text
    By SamSong in forum Qt Programming
    Replies: 1
    Last Post: 14th June 2009, 01:19
  5. QTextEdit + paste rich text as plain text only
    By Yong in forum Qt Programming
    Replies: 2
    Last Post: 6th February 2008, 17:45

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.