QPainter 未激活
以下代码会导致一堆错误:
void MainWindow::displayBoard()
{
QPixmap pix(0,0);
pix.fill(Qt::white);
QPainter painter(&pix);
painter.setBrush(Qt::black);
for(int row = 0; row < 8; row++)
for(int col = 0; col < 8; col++)
painter.drawRect(row * 10, col * 10, 10, 10);
ui->label->setPixmap(pix);
}
错误:
QPainter::begin: Paint device returned engine == 0, type: 2
QPainter::setBrush: Painter not active
QPainter::drawRects: Painter not active
如何解决此错误?
The following code results in a bunch of errors:
void MainWindow::displayBoard()
{
QPixmap pix(0,0);
pix.fill(Qt::white);
QPainter painter(&pix);
painter.setBrush(Qt::black);
for(int row = 0; row < 8; row++)
for(int col = 0; col < 8; col++)
painter.drawRect(row * 10, col * 10, 10, 10);
ui->label->setPixmap(pix);
}
The errors:
QPainter::begin: Paint device returned engine == 0, type: 2
QPainter::setBrush: Painter not active
QPainter::drawRects: Painter not active
How can I resolve this error?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题在于,正如 Colin 指出的那样,
pix
的大小为零。The problem was that, as Colin pointed out,
pix
was size zero.