PDA

View Full Version : QSplashScreen transparncy



vajindarladdad
12th October 2009, 11:48
Hi all Expert,
I am designing a custom SplashScreen , I have set a pixmap to it which has some transparent part in it . I have loaded a new image to the splashScreen in its drawContents( ) function to certain location.
But I am not able to set the splachscreen fully transparent so that i can see my desktopImage through it.I had tried several options mentioned in the forum but unfortunately that did'nt work.
Please let me know where i am going wrong.
.h file


class CustomSplashScreen:public QSplashScreen
{
Q_OBJECT
public:
CustomSplashScreen(const QPixmap& pixmap);
~CustomSplashScreen();
protected:
virtual void drawContents(QPainter *painter);
void paintEvent(QPaintEvent *event);
};


.cpp file


CustomSplashScreen::CustomSplashScreen(const QPixmap& pixmap)
{
QSplashScreen::setPixmap(pixmap);
}

CustomSplashScreen::~CustomSplashScreen()
{
}

void CustomSplashScreen::drawContents(QPainter *painter)
{
QImage image("://images/3.png");
painter->drawImage(-2,-2,image);
}

void CustomSplashScreen::paintEvent(QPaintEvent *event)
{
QPainter *painter = new QPainter(this);
setAttribute(Qt::WA_NoSystemBackground);
}

I want the result like final_Result_splashScreen.png

yogeshgokul
12th October 2009, 12:06
You need to call
QSplashScreen::setMask()

vajindarladdad
12th October 2009, 12:17
Hi Yogesh Sir,
i tried to set the mask , when i set the mask the spashsceen.png which is used to in function setPixmap() is shown ,but 3.png which is used in drawContents () is not shown.
Please let me know where i am going wrong.

yogeshgokul
12th October 2009, 12:22
Make sure, your image is transparent.

vajindarladdad
12th October 2009, 12:34
Yes sir, it is transparent.
The thing is i am loading two images first is in constructor & second is in drawContents()
The second image is partly on the first image.
I have tried many options but unfortunately nothing worked.
Please give me a hint.

yogeshgokul
12th October 2009, 13:06
Please run and see this example, use attached image.

#include <QApplication>
#include <QLabel>
#include <QBitmap>

int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QLabel lbl;
QPixmap pixmap("yell.png");
lbl.setPixmap(pixmap);
lbl.setMask(pixmap.mask());
lbl.show();
app.setQuitOnLastWindowClosed(true);
return app.exec();
}

vajindarladdad
12th October 2009, 13:12
This one gives me perfect result that i want.
But in my case insted of QLabel it is QSplashScreen ..and instead of 1 image i have used 2 images.
What i have to do in this case ?