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 QPainter
I get the following warnings.
QWidget::paintEngine: Should no longer be called
QPainter::begin: Paint device returned engine == 0, type: 1
Here is the code (SO answer, with a button it seems to work):
void CDerivedFromQTableView::paintEvent(QPaintEvent *event)
{
QTableView::paintEvent(event); // draw original content
QPainter p(this); // Problem: QPainter::begin: Paint device returned engine == 0, type: 1
const QPixmap pm(QPixmap::grabWidget(this->m_loadIndicator));
QPoint middle = this->geometry().center();
int x = middle.x() - pm.width() / 2;
int y = middle.y() - pm.height() / 2;
p.drawPixmap(QPoint(x, y), pm); // draw load indicator inside QTableView
}
I am surprised creating the QPainter
fails, so why is that. What am I doing wrong?
The simplified version still gives the warning
QPainter p(this);
QTableView::paintEvent(event);
return;
Warning (of course) gone when I comment out QPainter
, so it really seems to be the root cause, but why?
QPainter painter(this);
instead ofQPainter(this);
. – Stpierre