QPainter::begin: Painter already active
时间: 2023-12-11 10:44:32 浏览: 21
这个问题通常是由于没有及时结束之前的绘画操作导致的。在使用QPainter对象进行绘画时,需要确保在开始新的绘画操作之前,先调用end()方法结束之前的绘画操作。如果没有及时结束之前的绘画操作,就会产生类似于"QPainter::begin: Painter already active"的错误。因此,建议在每次使用QPainter对象进行绘画操作时,都要先检查是否之前的绘画操作已经结束,如果没有结束,就先调用end()方法结束之前的绘画操作。
相关问题
QPainter::translate: Painter not active QPainter::rotate: Painter not active
这个错误通常发生在没有开始绘制之前调用了QPainter的绘图函数。请确保您已经调用了begin()函数来开始绘制,例如:
```
QPainter painter(this); // this为绘制的目标设备,例如QWidget或QPixmap
painter.begin(this); // 开始绘制
// 绘制代码,例如:
painter.drawPixmap(agvs[i].current_x*25+200-(agv_size-nodeSize)/2,(agvs[i].current_y+1)*25+50-(agv_size-nodeSize)/2,agv_size,agv_size,QPixmap(":/new/prefix1/agv1.png").scaled(25,25));
painter.translate(agvs[i].current_x*25+200, (agvs[i].current_y+1)*25+50);
painter.rotate(agvs[i].angle_);
painter.drawPixmap(-agv_size/2, -agv_size/2, agv_size, agv_size, agvPixmap.scaled(25, 25).transformed(QTransform().rotate(agvs[i].angle_)));
painter.end(); // 结束绘制
```
这里我们使用QPainter的begin()函数开始绘制,然后在绘制代码中调用translate()和rotate()函数。最后,我们使用end()函数结束绘制。
QPainter::setBrush: Painter not active
This error message typically appears when you attempt to set the brush property of a QPainter object that is not currently active.
A QPainter object must be activated before it can be used to draw on a widget or other paint device. To activate a QPainter object, you can call the begin() method and pass in a pointer to the paint device you want to draw on.
For example, if you want to draw on a QWidget named myWidget, you could activate a QPainter object like this:
QPainter painter;
painter.begin(myWidget);
Once the QPainter object is active, you can set the brush property using the setBrush() method. However, if you attempt to call setBrush() on an inactive QPainter object, you will see the "Painter not active" error message.
To fix this error, make sure that your QPainter object is active before attempting to set any of its properties. If you're still having trouble, double-check that you're passing in a valid paint device to the begin() method.