PDA

View Full Version : Splash screen application like with transparent background ... how to ?



yellowmat
21st February 2006, 15:05
Hi,

I have an application with a pixmap as background (it is not an application with a palette background pixmap, just an application that has a pixmap used as background). The pixmap is a png one with some transparency.

What I want to do is display my application like a splash screen (no title, no status bar) with its background (the pixmap) transparent (only the transparent part of the png bitmap).

I am able to display my application as a splash screen (I use some flags for it), the transparent part of the pixmap is transparent but I still see the application background color.

I don't know how to do it, could someone help me ?

Thanks in advance

ReilenBlaeyze
21st February 2006, 15:58
I used teh google to look for examples of creating non-rectangular windows.. which it seems you want to do:

http://www.ida.liu.se/~TDDB28/kursbibliotek/Qt/examples/tux

Good luck with it... :)

bpetty
8th December 2006, 00:29
So here is the jist of the example code

QString fn="tux.png";

QImage img( fn );
QPixmap p;
p.convertFromImage( img );
if ( !p.mask() )
if ( img.hasAlphaBuffer() ) {
QBitmap bm;
bm = img.createAlphaMask();
p.setMask( bm );
} else {
QBitmap bm;
bm = img.createHeuristicMask();
p.setMask( bm );
}
MoveMe w(0,0,Qt::WStyle_Customize|Qt::WStyle_NoBorder);
w.setBackgroundPixmap( p );

And here is my updated 4.2 version:

QString sImageFile = "C:/Documents and Settings/bpetty/My Documents/My Pictures/face.JPG";

QImage BGImage(sImageFile);
QPixmap BGPixmap;
QPalette BGPalette;
QBitmap BGBitmap;

BGPixmap.fromImage(BGImage); // Create Image
if (!BGPixmap.mask())
{
if (BGImage.hasAlphaChannel())
{
BGImage = BGImage.createAlphaMask();
} else {
BGImage = BGImage.createHeuristicMask();
}

BGBitmap.fromImage(BGImage);
BGPixmap.setMask(BGBitmap);
}

BGPalette.setBrush(this->backgroundRole(), QBrush(BGPixmap)); // Create Palette

this->setFixedSize(BGImage.width(), BGImage.height()); // Set Window Size

this->setPalette(BGPalette); // Set Background Image

My code is displaying a black box... not the image. Am I doing something wrong? Is there an easier way to set the background of a dialog widget to an image?

I am also doing this:

CINWaitSplash(QWidget * parent = 0, Qt::WindowFlags f = Qt::SplashScreen|Qt::WindowStaysOnTopHint);

Could any of that be effecting it?

Brandybuck
8th December 2006, 19:51
You can't directly create transparent windows with Qt (at least, not yet). Your underlying windowing system may be able to do it however, so check there.

But what you can do is to create shaped windows. This is a different concept than transparency, but may be the effect you want. See the Qt example program "shapedclock" for more information.