Important: Please read the Qt Code of Conduct -

reimplement paintEngine() to return 0

  • Hello,

    I'm trying to port an widget written for Qt4 over to Qt5 (PyQt, I'm sorry if I'm posting in the wrong area of the forums). So far everything is going very smooth except for one thing.

    The widget has areas that are supposed to be transparent. I've been using the attributes Qt.WA_NoSystemBackground and Qt.WA_TranslucentBackground in order to make this work.

    Whenver a compositing manager is running this totally work fine (so Mac and Windows have no problems), but I found that (depending on the type of installation) Linux sometimes has trouble with this.
    Therefore I added a line to the code, setting the WA_PaintOnScreen attribute whenever the code is run on Linux. Instead of a solid background, it will then paint on top of the application.

    This used to work fine in Qt4, however, Qt5 starts throwing errors:

    QWidget::paintEngine: Should no longer be called
    QPainter::begin: Paint device returned engine == 0, type: 1
    QPainter::save: Painter not active
    QPainter::translate: Painter not active
    QPainter::setClipRect: Painter not active
    QPainter::pen: Painter not active
    QPainter::setPen: Painter not active
    QPainter::restore: Unbalanced save/restore

    When removing the WA_PaintOnScreen attribute, the errors go away.

    After some googling I think what I have to do is to 'reimplement paintEngine() to return 0'. However, I'm not sure how to do this.

    Any help would be much appreciated.

    As you might have figured, I'm not a profressional programmer.

    Thanks in advance

  • Lifetime Qt Champion


    Can you reproduce that with a minimal runnable code ?

    What version of PyQt and Qt are you using ?
    What Linux distribution ?
    What desktop environment ?

Log in to reply