views:

172

answers:

2

Hi, I'm trying to paint a PNG file on a QsplashScreen. Im' trying to do it via QPaitner. The reason I want to do it via QPainter is because I want it to minimize smoothly (until it disappear), When I'm just repaiting it it doesn't looks smooth at all.

I passed the QSplashScreen to the QPainter constructor. When I call begin() in the QPainter with th e QSplashScreen as parameter it fails on the assert d->active. It happens in the same way when I supply Qpixmap.

What am I doing wrong? How should I initiate the QPainter's begin()?

Thanks.

+4  A: 

You want to create a subclass of QSplashScreen and re-implement drawContents. See the docs.

Use the painter they give you and you should be fine.

Adam W
Thanks, It did help me and I got my smooth transition.I still have one problem. From some reason, the original picture still lays there. What happens is that I first show the full size picture, then smoothly minimize it. The problem is that while the picture is being minimized, the original full size picture still remains in the background.I've tried to setVisible(false) for the first painting, and it didn't help...Any ideas?Thanks a lot.
Without actually seeing it, try playing with backgroundMode (http://doc.trolltech.com/4.6/qpainter.html#backgroundMode) and eraseRect (http://doc.trolltech.com/4.6/qpainter.html#eraseRect)
Adam W
A: 

Specifically about using QPainter, the docs for the begin method clearly state that only one painter can be active on a given paint device at one time, and also that using the constructor-version of QPainter automatically calls begin for the value you passed in. So if you are doing it as described in your question, like so:

QWidget *widget( ... );

QPainter painter( widget );
painter.begin( widget ); // <-- error, we already have a painter active on that paint device (our own).
// Do stuff...
painter.end();

It could be that Qt should close the device first, then open the new one, but code like the above means you don't completely understand how QPainter works. You should almost always be using the version where you pass a device to the constructor, and never need to call begin or end. (Occasionally, you might keep the painter around a long time, and specifically use begin and end on it -- in that case, you shouldn't be initializing it to a device.)

Caleb Huitt - cjhuitt
I would disagree with the last part. If you are just beginning you should always be overriding paint or draw events using the QPainter given to you. But either way, you should read the documentation for the functions you use.
Adam W