paintEvent in QTableView derived class: Paint device returned engine == 0, type: 1

牧云@^-^@ 提交于 2019-11-28 14:15:21

As QTableView is a subclass of QAbstractScrollArea you should open QPainter on its viewport:

void CDerivedFromQTableView::paintEvent(QPaintEvent *event)
{
    QTableView::paintEvent(event); // draw original content

    QPainter p(this->viewport());
    p.drawRect(0, 0, 20, 20);
}

The docs say it:

This event handler can be reimplemented in a subclass to receive paint events (passed in event), for the viewport() widget.

Note: If you open a painter, make sure to open it on the viewport().

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!