報錯:QPainter::drawPath: Painter not active
时间: 2023-12-11 09:33:16
浏览: 72
这个错误通常是由于没有正确使用绘图上下(`QPainter`)致的。请确在绘制路径之前调了 `be[gin](https://geek.csdn.net/educolumn/1aef582107c22aa4d9f243890549bf39?spm=1055.2569.3001.10083)` 方法,并在完成绘制后用 `end` 方法。以下是一个例:
```cpp
QWid[get](https://geek.csdn.net/educolumn/31aebce56f4ecc5451aac3a194ff6259?spm=1055.2569.3001.10083)* widget = QWidget(this);
widget->setMinimumSize(, 400);
QPainter painter(widget);
painter.be[gin](https://geek.csdn.net/educolumn/1aef582107c22aa4d9f243890549bf39?spm=1055.2569.3001.10083)(widget);
// 在此处进行绘图操作,包括绘制路径
painter.end();
请确保在 `be[gin](https://geek.csdn.net/educolumn/1aef582107c22aa4d9f243890549bf39?spm=1055.2569.3001.10083)` 和 `end` 之间进行绘图操作,并且 `QPainter` [对象](https://geek.csdn.net/educolumn/04c51611e4b730957464192e0307b82c?spm=1055.2569.3001.10083)的生命周期在这之间。这样可以确保绘图上下文处于活动状态,避免出现 "Painter not active" 的错误。
相关问题
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 t