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