简体   繁体   English

调用开始时QPainter失败

[英]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()?

You want to create a subclass of QSplashScreen and re-implement drawContents . 您要创建QSplashScreen的子类并重新实现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: 特别是关于使用QPainterbegin方法的文档清楚地指出,一次只能在给定的绘画设备上激活一个绘画者,并且使用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 . 您几乎应该始终使用将设备传递给构造函数的版本,并且永远不需要调用beginend (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.) (有时,您可能需要长时间保留绘画者,并且特别要在其上使用beginend -在这种情况下,您不应该将其初始化到设备上。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 QPainter :: begin在调试模式下使程序崩溃 - QPainter::begin crashes the program in debug mode QPainter :: begin:绘制设备返回的引擎== 0,键入:2 - QPainter::begin: Paint device returned engine == 0, type: 2 QPainter :: begin:小部件绘画只能作为paintEvent的结果开始 - QPainter::begin: Widget painting can only begin as a result of a paintEvent QListWidgdet resizeEvent QPainter :: begin:绘制设备返回的引擎== 0,类型:2 - QListWidgdet resizeEvent QPainter::begin: Paint device returned engine == 0, type: 2 移动QWidget时QPainter黑色轨迹 - QPainter black trace when moving QWidget 在QPixmap上使用QPainter时应用崩溃 - App crash when using QPainter on QPixmap 调用OpenCV方法时,CoInitializeEx失败cvLoadImage() - CoInitializeEx fails when calling OpenCV method cvLoadImage() 如何在QScrollArea上绘制QImage? 做到了这一点,但有一些小问题QPainter :: begin:小部件绘画只能作为paintEvent的结果开始 - How to draw QImage on QScrollArea? Did this, but have some minor problems QPainter::begin: Widget painting can only begin as a result of a paintEvent 调用Qpainter的方法paint刷新图像并更改颜色 - Calling Qpainter's method paint to refresh image and change color 调用wxListCtrl :: EditLabel(index)时无法捕获EVT_LIST_BEGIN_LABEL_EDIT事件 - Can't catch EVT_LIST_BEGIN_LABEL_EDIT event when calling wxListCtrl::EditLabel (index)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM