Important: Please read the Qt Code of Conduct -

How to convert QPainter(self) to QImage?

  • I want to apply blur to a version of my painted circle to be placed under the original circle for additional effect. Because I couldn't find a way to directly apply a blur filter to QPainter, or the widget, I found this method:

    blur = QtWidgets.QGraphicsBlurEffect()
    result = applyEffectToImage(img, blur)"N:/sample.bmp")
    def applyEffectToImage(src, effect):
        scene = QtWidgets.QGraphicsScene()
        item = QtWidgets.QGraphicsPixmapItem()
        res = QImage(src.size(), QImage.Format_ARGB32)
        ptr = QPainter(res)
        scene.render(ptr, QRectF(), QRectF(0,0, src.width(), src.height()) )
        return res

    But if I create an img and pass it to QPainter, it will have the same artifact shown here:

    So I must use QPainter(self).

    How can I convert my QPainter(self) to a QImage?

    I just want to draw a circle (which I did), blur it, place this blurry version under the original circle. Is there a simpler or better way to do this other than this?

    Thanks in advance.

  • QPainter(self) is highly dependent upon what self is. Have you reviewed the QPainter and QPaintDevice documentation?

  • You seem to not understand what QPainter is or what it does, QPainter is a painter who paints on a canvas(self object) that can be a QImage, QPixmap, QWidget, etc. so you cannot convert the painter into QImage, what you can do is convert the canvas to QImage.

  • From what I understand you you want to have a QImage that shows a circle where the filter blur was applied. I am right?

Log in to reply