Results 1 to 11 of 11

Thread: insert hyperlink(URL) inside the TextEdit..

  1. #1
    Join Date
    Jan 2011
    Posts
    42
    Thanks
    8
    Qt products
    Qt4 Qt/Embedded

    Default insert hyperlink(URL) inside the TextEdit..

    Hi, i can add the path to textedit area, but i want that url to be like a hyperlink. Does any1 got any idea?? All i need is that , the URL which i am inserting sholud be Clickable format.
    Even i tried with the QTextBrowser and QTextCharFormat. i couldnt find out the solution.

    I will be very much thankful. Pleassseeeeeeeee.

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: insert hyperlink(URL) inside the TextEdit..

    What about inserting HTML instead of plain text?

  3. #3
    Join Date
    Jan 2011
    Posts
    42
    Thanks
    8
    Qt products
    Qt4 Qt/Embedded

    Default Re: insert hyperlink(URL) inside the TextEdit..

    textedit.insertHtml will insert only the link/path. but the path is not highlighted like a URL. please reply if u know the answer.

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: insert hyperlink(URL) inside the TextEdit..

    I was talking about interting HTML, not inserting plain text via the setHtml function. You might also want have a look at the textInteractionFlags.
    (If you would have post some code what you have tried, it would be easier to help.)

  5. #5
    Join Date
    Jan 2011
    Posts
    42
    Thanks
    8
    Qt products
    Qt4 Qt/Embedded

    Default Re: insert hyperlink(URL) inside the TextEdit..

    Qt Code:
    1. void TextPad::inserturl()
    2. {
    3.  
    4. bool ok;
    5. QString baseUrl= QInputDialog::getText(this, tr("URL"),tr("Link:"), QLineEdit::Normal, "", &ok);
    6. ui->textEdit->setHtml(baseUrl);
    7.  
    8. }
    To copy to clipboard, switch view to plain text mode 

    This is like, a dialog will open and i will enter the URL in that. aftr that the url is displayed in the textedit, but not as a hyperlink.

    Waiting for ur reply
    Last edited by Lykurg; 5th January 2011 at 09:08. Reason: missing [code] tags

  6. #6
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: insert hyperlink(URL) inside the TextEdit..

    Yeah, I guessed that... look:
    Qt Code:
    1. ui->textEdit->setHtml("http://qtcentre.org");
    To copy to clipboard, switch view to plain text mode 
    inserts plain text even if you use setHtml. But with that
    Qt Code:
    1. ui->textEdit->setHtml("<a href=\"http://qtcentre.org\">http://qtcentre.org</a>");
    To copy to clipboard, switch view to plain text mode 
    you insert HTML. You might also want to check the user input first.

  7. The following user says thank you to Lykurg for this useful post:

    rleojoseph (7th January 2011)

  8. #7
    Join Date
    Jan 2011
    Posts
    42
    Thanks
    8
    Qt products
    Qt4 Qt/Embedded

    Default Re: insert hyperlink(URL) inside the TextEdit..

    Thank u very much! That is working but the link is not like a clickable format .

    This is what am going to do. Insert a URL in a TextEdit and click the link that will open in a default browser or Webview.

    But my work is to load the the URL from the Dialog Box.
    QString baseUrl= QInputDialog::getText(this, tr("URL"),tr("Link:"), QLineEdit::Normal, "", &ok);
    ui->textEdit->setHtml(???????);

  9. #8
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: insert hyperlink(URL) inside the TextEdit..

    Well I won't write the program for you. See textInteractionFlags(), check for a signal which is emitted when someone clicks the link and react on that bay opening the default browser etc. See also QDesktopServices.

    And NOTICE the [CODE] tags!

  10. The following user says thank you to Lykurg for this useful post:

    rleojoseph (7th January 2011)

  11. #9
    Join Date
    Jan 2011
    Posts
    42
    Thanks
    8
    Qt products
    Qt4 Qt/Embedded

    Default Re: insert hyperlink(URL) inside the TextEdit..

    Thanks a lot again!! Am working on it. I have another question,If you wish you can reply. is it possible to embed a link to a image. I mean using the image as a link. Its like , embedding the link/path of a file to that image.


    Thanks in Advance!!!!

  12. #10
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: insert hyperlink(URL) inside the TextEdit..

    Yes it is possible and all related the HTML. See the img tag: http://www.w3schools.com/tags/tag_img.asp. (Also handy: the Qt resource System)

  13. The following user says thank you to Lykurg for this useful post:

    rleojoseph (7th January 2011)

  14. #11
    Join Date
    Jan 2011
    Posts
    42
    Thanks
    8
    Qt products
    Qt4 Qt/Embedded

    Default Re: insert hyperlink(URL) inside the TextEdit..

    Am workin on QT4.7. Lets say am selecting a file like *.doc and instead of opening it i am goin to insert a image/icon in a TEXTEDIT.Now when i click that IMAGE the *.doc file should open. Thats why i thought of inserting an image when a file is selected, and when i click the image the file should open.

Similar Threads

  1. Insert line to textedit
    By wirasto in forum Qt Programming
    Replies: 1
    Last Post: 18th December 2009, 15:59
  2. Replies: 0
    Last Post: 4th November 2009, 06:12
  3. Insert SVG inside QTextDocument
    By giusepped in forum Qt Programming
    Replies: 6
    Last Post: 23rd April 2009, 19:57
  4. [Qt4.1] How to insert an image inside a Form?
    By Gonzalez in forum Qt Tools
    Replies: 5
    Last Post: 23rd September 2008, 11:20
  5. How to create a HyperLink in Qt?
    By vishal.chauhan in forum Newbie
    Replies: 1
    Last Post: 27th March 2007, 14:03

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.