PDA

View Full Version : Insert an image with transparent background on base background



mrphunghuy
31st October 2013, 08:12
Hello Everybody!
I'm a newbie of Qt. I have a problem need help. I want insert an image with transparent background (icon-home.png) in to a window which I created.
This window I set background by follow command:


window->setStyleSheet("background-image: url(./images/bg.jpg");

Image I insert by:

QLabel *image = new QLabel;
image->setPixmap(QPixmap("./images/icon-home.png"));

Then:

layout->addWidget(image);
window->setLayout(layout);

but when program run, the area transparent of image haven't color of base background (otherwise, the area stransparent of image cover base background).
How to make this area transparent dont cover base background ?
Thanks!

sonulohani
31st October 2013, 11:43
Try This:


setStyleSheet("background-image: url(:/bg.jpg)");
QLabel *image = new QLabel(this);
image->setPixmap(QPixmap(":/icon-home.png"));

Make sure your images are available in the resource file with prefix "/".

mrphunghuy
31st October 2013, 15:38
It work! Thanks you!

Vivek1982
27th November 2013, 08:41
hi.. how to move the image which u have inserted on the top of background. based on the certain time intervals inserted image can change the location ont he background. something like tracking of the objects/devices/systems.

Thanks in advance.

aamer4yu
27th November 2013, 15:15
For custom drawing , you will need to override the QWidget::paintEvent function.