Qt QWidget::paintEngine: Should no longer be called 错误的解决办法

今天在重写QListView的 paintEvent方法时 

QPainterpainter(this);
painter.drawText(rect(),Qt::AlignCenter,tr("Draganddropfile(s)here"));

运行时遇到了如下问题(并且文字并没有显示):


QWidget::paintEngine: Should no longer be called

QPainter::begin: Paint device returned engine == 0, type: 1


其解决思路是:

将QPainter painter(this);这一句改成QPainter painter(this->viewport());


我的问题就解决了

你可能感兴趣的:(Qt QWidget::paintEngine: Should no longer be called 错误的解决办法)