Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QPainter not active

Tags:

c++

qt

qpainter

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?

like image 918
wrongusername Avatar asked Feb 04 '23 00:02

wrongusername


1 Answers

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

like image 71
wrongusername Avatar answered Feb 05 '23 18:02

wrongusername