PDA

View Full Version : set background image for frames and labels



saman_artorious
30th March 2013, 17:31
as to drop some images inside a frame, with its background image loaded, you may use this:


frame->setStyleSheet("background:black;background-position: center; background-image: url(:/truck/image.png);background-repeat: no-repeat; ");


Although widgets fall on top of the image, this way was not nice for me as frame does not have setPixmap(). So, in order to scale my image to fit the template, I used a QLabel instead. This was a nice way as you may see:


QImage myImage;
myImage.load(":/truck/image.png");
QImage image = myImage.scaled(love->width(), love->height(), Qt::IgnoreAspectRatio );
love->setPixmap(QPixmap::fromImage(image));

here, love is a QLabel ;) . anyway, I found this way pretty disappointing as widgets now disappear and they do not fall on top of the QLabel background image!

I both want to scale the image to fit the template as well as the widgets to fall on top of the image, do you have any idea how i can do that? and can you also explain why in the case of QLabel, widgets do not fall on top of the image.

saman_artorious
6th April 2013, 10:28
well, I reply to my own post. We can apply HTML tags in a Label with setText() function:


QLabel *label = new QLabel();
label->setText("<img src='your_image_path'/><br>SomeText");