Results 1 to 8 of 8

Thread: Hyperlink text in QLabel to open web browser

  1. #1
    Join Date
    May 2012
    Posts
    99
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Question Hyperlink text in QLabel to open web browser

    Hi all,

    I'm developing an about window. In this window I have some urls.

    For example, if my label has the text: "http://www.qtcentre.org" I want that when the user click in the label, the web browser opens with the specified url.

    What is the best way to perform this?

    Regards.

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

    Default Re: Hyperlink text in QLabel to open web browser

    You can use openExternalLinks

  3. #3
    Join Date
    May 2012
    Posts
    99
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Question Re: Hyperlink text in QLabel to open web browser

    Hi Zlatomir,

    I have set openExternalLinks, LinksAccessibleByMouse and LinksAccessibleByKeyboard to true, but nothing happen when I click over the QLabel.

    What's wrong?

    Regards.

  4. #4
    Join Date
    Jul 2010
    Posts
    41
    Thanks
    6
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Hyperlink text in QLabel to open web browser

    Is it a link? I mean the text should be like this:
    Qt Code:
    1. QLabel label;
    2. label.openExternalLinks(true);
    3. label.setText("<a href=\"http://www.qtcentre.org\" />QtCentre</a>");
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    May 2012
    Posts
    99
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Question Re: Hyperlink text in QLabel to open web browser

    Hi srazi,

    I have used your code but nothing happens when I click over the label. Have you tested the code?

    Regards.

  6. #6
    Join Date
    Dec 2008
    Location
    Poland
    Posts
    383
    Thanks
    52
    Thanked 42 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Hyperlink text in QLabel to open web browser

    Did You set text format to Plain text on QLabel? If so change it to Auto / Rich text.
    In the near future - corporate networks reach out to the stars. Electrons and light flow throughout the universe.
    The advance of computerization however, has not yet wiped out nations and ethnic groups.

  7. #7

    Default Re: Hyperlink text in QLabel to open web browser

    hello world
    the right code is :
    QLabel label;
    label.openExternalLinks(true);
    label.setText("<a href=\"http://www.qtcentre.org\">QtCentre</a>");
    i tested and it's work

  8. #8
    Join Date
    Jun 2008
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Hyperlink text in QLabel to open web browser

    The really right code is:

    QLabel label;
    label.setOpenExternalLinks(true);
    label.setText("<a href="http://www.qtcentre.org">QtCentre</a>");

Similar Threads

  1. Replies: 1
    Last Post: 11th July 2011, 12:50
  2. Replies: 0
    Last Post: 17th March 2011, 03:17
  3. Open URL on Non Default Browser
    By sheeeng in forum Qt Programming
    Replies: 3
    Last Post: 27th July 2009, 07:34
  4. How to open a browser ?
    By probine in forum Qt Programming
    Replies: 1
    Last Post: 4th December 2006, 18:21
  5. open a browser
    By npc in forum Newbie
    Replies: 1
    Last Post: 5th April 2006, 10:23

Tags for this Thread

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.