问题
QWidget::paintEngine: Should no longer be calledQPainter::begin: Paint device returned engine == 0, type: 1QPainter::setPen: Painter not activeQPainter::drawPoints: Painter not active
程序运行的时候出现上述问题,说明此时下端代码并未被触发。
void Form::paintBorder(QWidget *widget)
{if (!m_isPress) {return ;}QPainter painter(widget);QPen pen;QColor color;if (m_isNudge) {QColor cl(Qt::red);color = cl;pen.setStyle(Qt::DashDotLine);}else {QColor cl(Qt::darkBlue);color = cl;pen.setStyle(Qt::SolidLine);}pen.setColor(color);pen.setWidth(6);painter.setPen(pen);QRect rect = this->rect();painter.setRenderHint(QPainter::Antialiasing);painter.drawRect(rect.x(),rect.y(),rect.width(),rect.height());
}
上述代码的执行,必须有某一个操作触发了重绘函数。这时QPainter才会被激活。像移动的窗口,会触发重绘函数对窗口重绘,当然应该只是对变化了部分进行重绘。像窗口被遮住,也会触发重绘函数对没有遮住的部分进行重绘。以上是本人的理解,欢迎吐槽。