PDA

View Full Version : QLabel with text and icon



franco.amato
26th January 2011, 17:48
Hi I would have a QLabel ( to show text in a status bar )
containing a small icon ( on the left size ) and some text on the right side.
Is possible ? Or should I create a new widget?
Best Regards,
Franco

high_flyer
26th January 2011, 18:01
Is possible ? Or should I create a new widget?
Which part of the StatusBar documentation was not clear, that I should explain here?

franco.amato
26th January 2011, 18:07
Which part of the QProgressBar documentation was not clear, that I should explain here?

I didn't get you.
Why QProgressBar?

high_flyer
26th January 2011, 18:13
Sorry I meant StatusBar of course.

franco.amato
26th January 2011, 20:01
Sorry I meant StatusBar of course.

Hi yes.
I splitted the statusbar in 3 parts. In the first part (0) I would display a text and a small icon and in the other parts I
would display only text. So I used Qlabel but it can't contain text+icon in the same QLabel or yes?
Regards

ChrisW67
26th January 2011, 21:41
QLabel displays either an icon or text. You could:

Use rich text for the label, e.g: label->setText("<img src=':/icon.png' /> Text of label"), and put the icon into the program resources.
Create a QWidget subclass that contains two QLabels in a horizontal layout and exposes a setIcon() and setText() method.
Create a custom widget with just-the-way-you-like-it paint() method.

franco.amato
26th January 2011, 22:56
QLabel displays either an icon or text, but not both. You could:

Use rich text for the label, e.g: label->setText("<img src=':/icon.png' /> Text of label"), and put the icon into the program resources.
Create a QWidget subclass that contains two QLabels in a horizontal layout and exposes a setIcon() and setText() method.
Create a custom widget with just-the-way-you-like-it paint() method.


Thank you very much

Added after 1 10 minutes:

Hi,
it works but the size of the icon broke the status bar. How can I force the ico to have a small size?
Regards

ChrisW67
26th January 2011, 23:10
Create a smaller icon :)

You can also set a height and/or width attribute on the img tag in the rich text option, but you get a scaled image which is often unsatisfying.

wysota
27th January 2011, 01:05
"Format c:" also helps ;)