以下代码会导致很多错误:

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

如何解决此错误?

最佳答案

问题是,正如Colin指出的那样,pix的大小为零。

关于c++ - QPainter无效,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4341707/

10-11 16:25