PDA

View Full Version : How to display icon from theme in QLabel?



Infinity
17th July 2013, 20:05
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:

<html><head/><body><p style="font-weight: bold"><img src=":/images/information.png"/> Currently there is no (supported) tag assigned.</p></body></html>

Is there an way to use an icon from theme in HTML code like it can be achieved using the following code:

QIcon::fromTheme(QStringLiteral("list-add"), QIcon(QStringLiteral(":/images/add")))

Thanks for you answers.

anda_skoa
20th July 2013, 18:13
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/qtextdocument.html#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,
_

Infinity
24th July 2013, 17:40
I have already expected, that I'll have to use a workaround. Thanks for answering anyhow.