Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to convert QPainter(self) to QImage?
Forum Updated to NodeBB v4.3 + New Features

How to convert QPainter(self) to QImage?

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 652 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    lachdanan
    wrote on last edited by
    #1

    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()
    blur.setBlurRadius(20)
    result = applyEffectToImage(img, blur)
    result.save(r"N:/sample.bmp")
    
            
    def applyEffectToImage(src, effect):
        scene = QtWidgets.QGraphicsScene()
        item = QtWidgets.QGraphicsPixmapItem()
        item.setPixmap(QPixmap.fromImage(src))
        item.setGraphicsEffect(effect)
        scene.addItem(item)
        res = QImage(src.size(), QImage.Format_ARGB32)
        res.fill(Qt.transparent)
        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:
    https://forum.qt.io/topic/111004/how-to-mask-a-widget-by-a-single-color-for-transparency/14

    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.

    1 Reply Last reply
    0
    • Kent-DorfmanK Offline
      Kent-DorfmanK Offline
      Kent-Dorfman
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • eyllanescE Offline
        eyllanescE Offline
        eyllanesc
        wrote on last edited by
        #3

        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.

        If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

        1 Reply Last reply
        0
        • eyllanescE Offline
          eyllanescE Offline
          eyllanesc
          wrote on last edited by
          #4

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

          If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved