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

后端 未结 1 399
终归单人心
终归单人心 2020-12-02 00:25

As a follow up of Qt load indicator by animated image (aka preloader) or alternative? I try to paint inside a QTableView. But when I initialize the QPaint

相关标签:
1条回答
  • 2020-12-02 01:26

    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().

    0 讨论(0)
提交回复
热议问题