开发者

QPainter fails when calling begin

开发者 https://www.devze.com 2022-12-17 19:08 出处:网络
I\'m trying to paint a PNG file on a QsplashScreen. Im\' trying to do it via QPainter. The reason I want to do it via QPainter is because I want it to minimize smoothly (until it disappear), When I\'m

I'm trying to paint a PNG file on a QsplashScreen. Im' trying to do it via QPainter. 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 b开发者_JAVA百科egin() 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()?


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.


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.)

0

精彩评论

暂无评论...
验证码 换一张
取 消