Results 1 to 4 of 4

Thread: QLabel links?

  1. #1
    Join Date
    Apr 2006
    Location
    San Francisco, CA
    Posts
    186
    Thanks
    55
    Thanked 12 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default QLabel links?

    Under the docs for QLabel, http://doc.trolltech.com/4.2/qlabel.html, it talks about a new property called openExternalLinks, which
    "Specifies whether QLabel should automatically open links using QDesktopServices :: OpenUrl() instead of emitting the anchorClicked() signal."

    Is this for real? Is it saying that I can set up a QLabel to be clickable, like a web-browser link, and perhaps have the mouse cursor change when it hovers over the link? If so, how do I set the text so that it can hyperlink to a webpage? I tried something like
    <a href=\"http://www.yahoo.com\">yahoo.com</a> but it wouldn't show up as a link, nor could I click on it.
    Software Engineer



  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QLabel links?

    Have you noticed this?

    Note: The textInteractionFlags set on the label need to include either LinksAccessibleByMouse or LinksAccessibleByKeyboard.

  3. #3
    Join Date
    Apr 2006
    Location
    San Francisco, CA
    Posts
    186
    Thanks
    55
    Thanked 12 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QLabel links?

    Yes, I had set the flags as well. But it still did not work, was not clickable, nor was it underlined. Is it automatically underlined or should that be done manually (<u> or such)?
    Software Engineer



  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QLabel links?

    This seems to work fine:
    Qt Code:
    1. #include <QApplication>
    2. #include <QLabel>
    3.  
    4. int main(int argc, char **argv){
    5. QApplication app(argc, argv);
    6. QLabel label;
    7. label.setTextInteractionFlags(Qt::LinksAccessibleByMouse);
    8. label.setOpenExternalLinks(true);
    9. label.setText("<a href=\"http://www.qtcentre.org\">QtCentre</a>");
    10. label.show();
    11. return app.exec();
    12. }
    To copy to clipboard, switch view to plain text mode 

    Maybe the html code tags were changed into entities? Did you setup the text using Designer?

  5. The following 2 users say thank you to wysota for this useful post:

    gfunk (2nd January 2007), ravas (24th March 2016)

Similar Threads

  1. QScrollArea display custom QLabel
    By spawnwj in forum Qt Programming
    Replies: 6
    Last Post: 6th December 2006, 03:38
  2. QLineEdit && QLabel
    By eleanor in forum Newbie
    Replies: 16
    Last Post: 12th November 2006, 17:30
  3. QT4 layout of complex dialog is very slow
    By cboles in forum Qt Programming
    Replies: 15
    Last Post: 28th April 2006, 19:57
  4. [Qt4.1]How to make links open browsers?
    By patcito in forum Qt Programming
    Replies: 8
    Last Post: 16th March 2006, 18:37
  5. QLabel with HTML-style formatting docs?
    By Everall in forum Qt Programming
    Replies: 6
    Last Post: 7th February 2006, 20:01

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.