Results 1 to 3 of 3

Thread: How to display icon from theme in QLabel?

  1. #1
    Join Date
    Oct 2012
    Posts
    132
    Thanks
    10
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default How to display icon from theme in QLabel?

    Hi,

    is it possible to display an icon from theme in a QLabel?

    I'm currently displaying an icon from the resources using the following HTML code as text:
    Qt Code:
    1. <html><head/><body><p style="font-weight: bold"><img src=":/images/information.png"/> Currently there is no (supported) tag assigned.</p></body></html>
    To copy to clipboard, switch view to plain text mode 

    Is there an way to use an icon from theme in HTML code like it can be achieved using the following code:
    Qt Code:
    1. QIcon::fromTheme(QStringLiteral("list-add"), QIcon(QStringLiteral(":/images/add")))
    To copy to clipboard, switch view to plain text mode 

    Thanks for you answers.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to display icon from theme in QLabel?

    That is unfortunately not so straight forward because QLabel does not give you access to its internal QTextDocument (see http://qt-project.org/doc/qt-4.8/qte...ml#addResource)

    I think you have basically three options
    1) save the pixmap from QIcon into a temporary file and reference it in the label text
    2) use a more advanced text widget instead of QLabel
    3) create your own widget that uses a QTextDocument to render the text, potentially putting it into a QFrame if you where using that aspect of QLabel.

    Cheers,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    Infinity (24th July 2013)

  4. #3
    Join Date
    Oct 2012
    Posts
    132
    Thanks
    10
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: How to display icon from theme in QLabel?

    I have already expected, that I'll have to use a workaround. Thanks for answering anyhow.

Similar Threads

  1. QLabel with text and icon
    By franco.amato in forum Newbie
    Replies: 8
    Last Post: 27th January 2011, 01:05
  2. Icon from theme
    By wirasto in forum Qt Programming
    Replies: 1
    Last Post: 22nd December 2009, 12:42
  3. Display QLabel in two lines
    By arunvv in forum Newbie
    Replies: 1
    Last Post: 8th February 2008, 05:25
  4. Replies: 2
    Last Post: 14th January 2008, 18:09
  5. Qlabel with (icon and text) HowTo ?
    By QiT in forum Qt Programming
    Replies: 2
    Last Post: 8th August 2006, 08:14

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.