9
votes

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?

1
The problem may be that your pixmap is of size 0x0 - Colin
@Colin yup that was it thanks! Want to try entering it as an answer? - wrongusername

1 Answers

12
votes

The problem was that, as Colin pointed out, pix was size zero.