[英]QPainter fails when calling begin
I'm trying to paint a PNG file on a QsplashScreen. 我正在尝试在QsplashScreen上绘制PNG文件。 Im' trying to do it via
QPainter
. 我正在尝试通过
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. 我想通过
QPainter
进行此操作的原因是因为我希望其平滑地最小化(直到消失),当我重新对其进行修补时,它看起来一点也不平滑。
I passed the QSplashScreen
to the QPainter
constructor. 我将
QSplashScreen
传递给QPainter
构造函数。 When I call begin() in the QPainter
with th e QSplashScreen
as parameter it fails on the assert d->active
. 当我使用
QSplashScreen
作为参数在QPainter
调用begin()时,它在断言d->active
上失败。 It happens in the same way when I supply Qpixmap
. 当我提供
Qpixmap
时,它以相同的方式发生。
What am I doing wrong? 我究竟做错了什么? How should I initiate the
QPainter
's begin()? 我应该如何启动
QPainter
的begin()?
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: 特别是关于使用
QPainter
, begin
方法的文档清楚地指出,一次只能在给定的绘画设备上激活一个绘画者,并且使用QPainter
的构造函数版本会自动调用您传入的值。如果您按照问题中的描述进行操作,例如:
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. Qt可能应该先关闭设备,然后再打开新设备,但是上面的代码意味着您不完全了解
QPainter
工作原理。 You should almost always be using the version where you pass a device to the constructor, and never need to call begin
or end
. 您几乎应该始终使用将设备传递给构造函数的版本,并且永远不需要调用
begin
或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.) (有时,您可能需要长时间保留绘画者,并且特别要在其上使用
begin
和end
-在这种情况下,您不应该将其初始化到设备上。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.