2010-12-03 120 views
7

下面的代码导致一堆错误: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 

我怎样才能解决这个问题?

+12

问题可能是你的像素大小为0x0 – Colin 2010-12-03 01:50:28

回答