I have both text and image in QLabel, so setPixmap won't satisfy my requirement.
As far as I know, QLabel can load image from file by setting HTML label <img src="path_to_file" />
. But how can I load image from memory(e.g. QImage)? Because some images are frequently used, it may have performance problem loading the same image from file every time.
Asked
Active
Viewed 1,818 times
0

hbprotoss
- 1,385
- 10
- 27
3 Answers
1
QLabel
accepts QPixmaps
, which can be constructed from QImage
. I do not know about the python interface, but maybe this helps:
In C++ you can set an image like this:
QLabel label;
QImage image("path_to_file");
QPixmap pixmap = QPixmap::fromImage(image);
label.setPixmap(pixmap);

bjoernz
- 3,852
- 18
- 30
0
You have two choices:
- use two labels, one with the text and one with the image.
- use a QPainter to draw the text over the image.

zzk
- 1,347
- 9
- 15
-
Could you explain more on 2? Do you mean cover the image with text on it? Because there are unknown number of image within the text, so 1 can't help. – hbprotoss Mar 04 '13 at 06:44
-
@hbprotoss check out this link: http://stackoverflow.com/questions/4270229/qt-how-to-set-text-on-top-of-qlabel-image – zzk Mar 04 '13 at 06:59
0
You can also set stylesheet for your QLabel as:- QLabel{ background-image: url(/images/button.png);

Nitish Jain
- 206
- 2
- 5