简体   繁体   中英

Qt - creating QPainter

I'm trying to rewrite method paintEvent in my programm and change it.

void MainWindow::paintEvent(QPaintEvent *event)
{
    QRegion reg = this->bgPixmapHandle->rect();
    QPainter painter(this);

    painter.setClipRegion(reg);
    painter.drawImage(bgPixmapHandle->rect(), bgPixmapHandle);
    painter.end();
}

Here I try to change my bg image. But I got an error on line: QPainter painter(this);

Error: Variable 'QPainter painter' is initialized, though the type is incomplete

Include QPainter header file. QPainter class is only forward declared in one of the Qt headers you're including in that translation unit.

#include <QPainter>

Are you including? Qt is a big fan of forward declaration of classes, which causes such cryptic errors.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM