调用开始时 QPainter 失败
我正在尝试在 QsplashScreen 上绘制 PNG 文件。 我正在尝试通过 QPainter 来完成此操作。我想通过QPainter来做到这一点的原因是因为我希望它能够平滑地最小化(直到它消失),当我刚刚重新修复它时,它看起来一点也不平滑。
我将 QSplashScreen
传递给 QPainter
构造函数。当我使用 QSplashScreen
作为参数调用 QPainter
中的 begin() 时,它在断言 d->active
上失败。当我提供 Qpixmap 时,也会以同样的方式发生。
我做错了什么?我应该如何启动QPainter
的begin()?
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 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()?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您想要创建
QSplashScreen
的子类并重新实现drawContents
。使用他们给你的油漆工,你应该没问题。
You want to create a subclass of
QSplashScreen
and re-implementdrawContents
.Use the painter they give you and you should be fine.
特别是关于使用 QPainter,begin 方法的文档明确指出,在给定的绘画设备上一次只能有一个画家处于活动状态,并且使用构造函数 -
QPainter
的版本会自动调用 begin 来获取您传入的值。因此,如果您按照问题中的描述进行操作,如下所示:Qt 可能应该首先关闭设备,然后打开新设备一,但是像上面这样的代码意味着您不完全理解 QPainter 是如何工作的。您几乎应该始终使用将设备传递给构造函数的版本,并且永远不需要调用
begin
或end
。 (有时,您可能会长时间保留绘图程序,并专门在其上使用begin
和end
——在这种情况下,您不应该将其初始化为设备。)Specifically about using
QPainter
, the docs for thebegin
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 ofQPainter
automatically calls begin for the value you passed in. So if you are doing it as described in your question, like so: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 callbegin
orend
. (Occasionally, you might keep the painter around a long time, and specifically usebegin
andend
on it -- in that case, you shouldn't be initializing it to a device.)