Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QWidget::paintEngine: Should no longer be called



  • Re: QWidget::paintEngine: Should no longer be called

    Qt/Examples/Qt-5.13.0/multimediawidgets/player

    The message presents itself in the Application Output window, a couple of times upon opening a MP4 video, then more upon selecting FullScreen. There is no explicit call to QWidget::paintEngine in player source code, but the Headers bring in qpaintengine.h and its override in qwidget.h:
    585 QPaintEngine *paintEngine() const override;
    The current docs mention nothing about why QWidget::paintEngine should no longer be called.

    Was QWidget::paintEngine deprecated?
    30Jul2019


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    No, it's not deprecated. The deprecation notice appears at build time.

    This message says that the painter has been called somehow at the wrong time.

    What OS are you on ?



  • I'm running Linux. I used the maintenance tool to install Qt 5.13.0. I was teaching myself how to use the UI Design Tool to create the Player interface, signals/slots. Built and ran the published Example player to make sure I had all of the correct buttons and icons, when I noticed all of the paintEngine messages.

    KDE Plasma v5.16.3, kernel 4.19.62, amdgpu with mesa 19.1.3, AMD ryzen5 2500U, Radeon Vega Mobile Gfx, llvm 8,0,1.



  • @sgaist

    When I put my QPainter in the main widget with the widget.ui, I got a blank widget with the following messages in the Application Output:

    QWidget::paintEngine: Should no longer be called
    QPainter::begin: Paint device returned engine == 0, type: 1
    QPainter::setPen: Painter not active
    

    I created a sub-widget class

    QWidget::paintEvent(QPaintEvent *event)
    

    moved all my drawing (QPainter::drawLines, QPen::setColor, QPointF, QLineF, QVector<QLineF>) into that class., leaving the main widget with only setupUI.

    No more messages, the ui widget now contains correctly rendered polygons.
    Perhaps we need to update some of the Examples?


  • Lifetime Qt Champion

    Can you show the exact change you did ?



  • I'm teaching myself how to draw lines. I gave up on the player example after I switched from full-screen esc back to normal and the player window detached, playing in a small box in the upper left corner of the screen while the player window had static wide black and white lines in it.
    This is what generated the above. No doubt better ways to do it, but it's a start.

    Widget::Widget(QWidget *parent) :
        QWidget(parent),
        ui(new Ui::Widget)
    {
        ui->setupUi(this);
    }
    
    Widget::~Widget()
    {
        delete ui;
    }
    
    void Widget::paintEvent(QPaintEvent *e)
    {
        // Base triangle
        qreal myWidthF  = this->width();
        qreal myHeightF = this->height();
    
        QPointF pt1, pt2, pt3;
        pt1.setX(0 + 1);
        pt1.setY(myHeightF - 1);
        pt2.setX(myWidthF/2 + 1);
        pt2.setY(0 + 1);
        pt3.setX(myWidthF - 1);
        pt3.setY(myHeightF - 1);
    
        QLineF side1, side2, side3;
        side1 = QLineF(pt1, pt2);
        side2 = QLineF(pt2, pt3);
        side3 = QLineF(pt3, pt1);
    
        QVector<QLineF> myTriangle;
        myTriangle << side1 << side2 << side3;
    
        QPainter mypainter(this);
        QPen mypen(Qt::blue);
    
        mypainter.setPen(mypen);
        mypainter.drawLines(myTriangle);
    


  • ...the rest. Next phase is to use recursion to make a Sierpinski Triangle.

    // Inner triangle
    pt1.setX(pt1.x() + side1.dx()/2);
    pt1.setY(pt1.y() + side1.dy()/2);
    
    pt2.setX(pt2.x() + side2.dx()/2);
    pt2.setY(pt2.y() + side2.dy()/2);
    
    pt3.setX(pt3.x() + side3.dx()/2);
    pt3.setY(pt3.y() + side3.dy()/2);
    
    side1 = QLineF(pt1, pt2);
    side2 = QLineF(pt2, pt3);
    side3 = QLineF(pt3, pt1);
    myTriangle.clear();
    myTriangle << side1 << side2 << side3;
    
    mypainter.setPen(Qt::red);
    mypainter.drawLines(myTriangle);

Log in to reply