调用开始时 QPainter 失败

发布于 2024-08-18 08:19:26 字数 388 浏览 7 评论 0原文

我正在尝试在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夏见 2024-08-25 08:19:26

您想要创建 QSplashScreen 的子类并重新实现 drawContents

使用他们给你的油漆工,你应该没问题。

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

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

非要怀念 2024-08-25 08:19:26

特别是关于使用 QPainter,begin 方法的文档明确指出,在给定的绘画设备上一次只能有一个画家处于活动状态,并且使用构造函数 - QPainter 的版本会自动调用 begin 来获取您传入的值。因此,如果您按照问题中的描述进行操作,如下所示:

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();

Qt 可能应该首先关闭设备,然后打开新设备一,但是像上面这样的代码意味着您不完全理解 QPainter 是如何工作的。您几乎应该始终使用将设备传递给构造函数的版本,并且永远不需要调用 beginend。 (有时,您可能会长时间保留绘图程序,并专门在其上使用 beginend ——在这种情况下,您不应该将其初始化为设备。)

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文