PDA

View Full Version : Showing a splash screen with transparency.



kremuwa
20th July 2010, 22:35
Hello,

In my app, I've got such a piece of code:

QSplashScreen splashScreen(QPixmap(":/data/other/splashScreen.png"));
splashScreen.show();
splashScreen.showMessage(QString("Loading..."),Qt::AlignCenter | Qt::AlignBottom,QColor(0,150,255));

MainWindow w;
splashScreen.finish(&w);
w.show();

It shows me a splash screen, but in places that should be transparent (as the base for this splash screen is a PNG image) there is background. Is this possible to have a splash screen with transparency?

borisbn
21st July 2010, 04:39
Did you try to set opacity (http://doc.qt.nokia.com/4.6/qwidget.html#windowOpacity-prop) property to your splash window?

kremuwa
22nd July 2010, 09:09
But I want only the transparent placec from PNG to be transparent and this doesn't seem to help me with that.

aamer4yu
22nd July 2010, 11:29
Try to play with Qt::WA_TranslucentBackground

tsp
22nd July 2010, 13:42
I have next piece of code in my project and it produces transparent background for png-image I use.



QPixmap pixmap(":/images/splash.png");
QSplashScreen splash(pixmap);
splash.setMask(pixmap.mask());
splash.show();

kremuwa
23rd July 2010, 11:17
Thank you very much for your responses. Unfortunately, Qt::WA_TranslucentBackground (together with Qt::FramelessWindowHint flag passed to the splash screen constructor) didn't work - it made the splash screen completely transparent - not only its "transparent places" from PNG. Tsp, your solution works well :).

raedbenz
21st August 2010, 09:41
hello i tried this but no joy.


#include <QtGui/QApplication>

#include<QTimer>
#include <QSplashScreen>
#include <QMainWindow>

int main(int argc, char *argv[])
{

QApplication a(argc, argv);

QPixmap pixmap(":/splash.png");
QSplashScreen splash(pixmap);
//splash.setMask(pixmap.mask());

splash.showMessage(QString("Loading..."),Qt::AlignCenter | Qt::AlignBottom,QColor(0,150,255));
splash.show();


QMainWindow mainWin;

QTimer::singleShot(1500, &splash, SLOT(close()));

QTimer::singleShot(1500, &mainWin, SLOT(show()));

return a.exec();

}

only the main window is displayed after timeout. the image splash.png is in my working directory.
if i uncomment splash.setMask(pixmap.mask()); i get: invalid use of incomplete type 'struct QBitmap' forward declaration of 'struct QBitmap'.

any hints? thanks

saa7_go
21st August 2010, 14:01
if i uncomment splash.setMask(pixmap.mask()); i get: invalid use of incomplete type 'struct QBitmap' forward declaration of 'struct QBitmap'.


You must include QBitmap header.



#include <QBitmap>

raedbenz
21st August 2010, 22:43
You must include QBitmap header.



#include <QBitmap>

thanks. but still no splash screen is displayed.

tsp
22nd August 2010, 06:37
image splash.png is in my working directory
Maybe the problem is in the way you are are referring to splash screen file i.e.


QPixmap pixmap(":/splash.png");
You are using :/ prefix, so the file should be defined in the resource (http://doc.qt.nokia.com/latest/resources.html) file, maybe you have not done that?

raedbenz
22nd August 2010, 08:42
Maybe the problem is in the way you are are referring to splash screen file i.e.


QPixmap pixmap(":/splash.png");
You are using :/ prefix, so the file should be defined in the resource (http://doc.qt.nokia.com/latest/resources.html) file, maybe you have not done that?

Hello,
i have added this, res.qrc

<!DOCTYPE RCC><RCC version="1.0">
<qresource>
<file>twirl.png</file>
<file>splash.png</file>
</qresource>
</RCC>
and when i compile i get :: error: [debug/qrc_res.cpp] Error 1

my project file is:


SOURCES += \
main2.cpp

RESOURCES += \
res.qrc

thanks

Bong.Da.City
12th September 2010, 22:46
I have next piece of code in my project and it produces transparent background for png-image I use.



QPixmap pixmap(":/images/splash.png");
QSplashScreen splash(pixmap);
splash.setMask(pixmap.mask());
splash.show();


Thanks.. It works :)