Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Draw a rectangle over an image
QtWS25 Last Chance

Draw a rectangle over an image

Scheduled Pinned Locked Moved Solved Qt for Python
27 Posts 5 Posters 5.6k Views
  • 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.
  • J Offline
    J Offline
    john_hobbyist
    wrote on 1 Mar 2022, 10:51 last edited by john_hobbyist 3 Jan 2022, 10:55
    #1

    I need to draw a green rectangle that is transparent inside, so only the green rectangle's lines to be visible, over an image, moreover to know its left top corner and right down corner coordinates. I have found code here: https://codeloop.org/pyqt5-drawing-rectangle-with-qpainter-class/ and here: https://zetcode.com/gui/pyqt5/painting/ I have managed to change the rectangle's lines to green. But I cannot change the inside of the rectangle to transparent.... in order to be able to depict the part of the image that the rectangle bounds...

    1 Reply Last reply
    0
    • M Offline
      M Offline
      Markkyboy
      wrote on 1 Mar 2022, 11:16 last edited by Markkyboy 3 Jan 2022, 11:41
      #2

      Hi, this works;

      EDIT: x and y positioning added!

      p.s. Apologies, I missed the part about python, I don't know/use python sorry.

      Window {
      width: 640
      height: 580
      visible: true
      title: qsTr("John_Hobbyist")

          Rectangle {
              width: 500
              height: width
              radius: 30
              color: "#00000000"
              border {
                  width: 10
                  color: "green"
              }
              Image {
                  anchors.centerIn: parent
                  source: "file:///C:/Users/Mark/Desktop/sailfish-green.png"
              }
              x: 125; y: 125
      
              Text {
                  id: label
                  text: qsTr("text")
                  anchors {
                      top: parent.bottom
                      horizontalCenter: parent.horizontalCenter
                  }
                  font.pixelSize: 72
              }
      
              function update() {
                  label.text = Math.round(x) + " x " + Math.round(y)
                  console.log("X: " + x + " x " + "Y: " + y)
              }
      
              onXChanged: update()
              onYChanged: update()
      
              Component.onCompleted: {
                  update()
              }
              MouseArea {
                  anchors.fill: parent
                  drag.target: parent
      
              }
          }
      }
      

      john-hobbyist.PNG

      Don't just sit there standing around, pick up a shovel and sweep up!

      I live by the sea, not in it.

      1 Reply Last reply
      1
      • J Offline
        J Offline
        john_hobbyist
        wrote on 1 Mar 2022, 11:21 last edited by
        #3

        I have built it in python. I will try to translate the above code (I think it is C++ ) to python and respond to you if it works...Thanks!

        K 1 Reply Last reply 1 Mar 2022, 11:23
        0
        • J john_hobbyist
          1 Mar 2022, 11:21

          I have built it in python. I will try to translate the above code (I think it is C++ ) to python and respond to you if it works...Thanks!

          K Offline
          K Offline
          KroMignon
          wrote on 1 Mar 2022, 11:23 last edited by
          #4

          @john_hobbyist said in Draw a rectangle over an image:

          I have built it in python. I will try to translate the above code (I think it is C++ ) to python and respond to you if it works...Thanks!

          This no C++ code, it is QML!!!

          It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

          1 Reply Last reply
          1
          • M Offline
            M Offline
            Markkyboy
            wrote on 1 Mar 2022, 11:42 last edited by
            #5

            Code updated @john_hobbyist - sorry, didn't read the part about python!....Oops!, speed reading again!

            Don't just sit there standing around, pick up a shovel and sweep up!

            I live by the sea, not in it.

            J 1 Reply Last reply 1 Mar 2022, 19:39
            1
            • M Markkyboy
              1 Mar 2022, 11:42

              Code updated @john_hobbyist - sorry, didn't read the part about python!....Oops!, speed reading again!

              J Offline
              J Offline
              john_hobbyist
              wrote on 1 Mar 2022, 19:39 last edited by
              #6

              @Markkyboy Sorry I do not know QML, moreover I have posted the question under "python" category...Thanks for your time though...

              1 Reply Last reply
              0
              • S Offline
                S Offline
                SGaist
                Lifetime Qt Champion
                wrote on 1 Mar 2022, 19:49 last edited by
                #7

                Hi,

                From memory: use a green QPen and a transparent QBrush.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                2
                • J Offline
                  J Offline
                  john_hobbyist
                  wrote on 2 Mar 2022, 15:04 last edited by john_hobbyist 3 Feb 2022, 15:12
                  #8

                  This is my try (source: https://stackoverflow.com/questions/61034583/drawing-a-circle-on-a-qwidget-python-gui and https://codeloop.org/pyqt5-drawing-rectangle-with-qpainter-class/). I cannot display the image and then above the image the green transparent rectangle...It depicts only the green rectangle and nothing behind...Why?

                  from PyQt5 import QtGui
                  import sys
                  from PyQt5.QtWidgets import *
                  from PyQt5.QtCore import *
                  from PyQt5.QtGui import *
                   
                  class Canvas(QWidget): 
                      def __init__(self, photo, *args, **kwargs): 
                          super().__init__(*args, **kwargs) 
                          
                          self.image = QImage(photo)
                          self.setFixedSize(self.image.width(), self.image.height())
                          self.pressed = self.moving = False
                          self.revisions = []
                   
                          self.title = "PyQt5 Drawing Rectangle"
                          self.top = 100
                          self.left = 100
                          self.width = 680
                          self.height = 500
                   
                          self.InitWindow()
                   
                      def InitWindow(self):
                          self.setWindowIcon(QtGui.QIcon("icon.png"))
                          self.setWindowTitle(self.title)
                          self.setGeometry(self.top, self.left, self.width, self.height)
                          self.show()
                   
                      def paintEvent(self, e):
                          painter = QPainter(self)
                          painter.setPen(QPen(Qt.green, 5, Qt.SolidLine))
                          painter.setBrush(QBrush(Qt.transparent))
                          painter.drawRect(100, 150, 400,200)
                  
                  class MainWindow(QMainWindow):
                  
                      def __init__(self):
                          super().__init__()
                          w = QWidget()
                          self.setCentralWidget(w)
                          canvas = Canvas('image3.png') 
                          grid = QGridLayout(w)
                          grid.addWidget(canvas)
                  
                  if __name__ == '__main__':
                      app = QApplication(sys.argv)
                      gui = MainWindow()
                      gui.show()
                      sys.exit(app.exec_())
                  
                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on 2 Mar 2022, 20:08 last edited by
                    #9

                    Because your are doing nothing with the image beside loading it and you are painting your rectangle in your widget and not on your image.

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    J 1 Reply Last reply 2 Mar 2022, 20:22
                    1
                    • S SGaist
                      2 Mar 2022, 20:08

                      Because your are doing nothing with the image beside loading it and you are painting your rectangle in your widget and not on your image.

                      J Offline
                      J Offline
                      john_hobbyist
                      wrote on 2 Mar 2022, 20:22 last edited by
                      #10

                      @SGaist Ok, what to add/fix in the code? Thanks...

                      1 Reply Last reply
                      0
                      • S Offline
                        S Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on 2 Mar 2022, 20:33 last edited by
                        #11

                        Paint the image before the rectangle.

                        Interested in AI ? www.idiap.ch
                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                        J 1 Reply Last reply 2 Mar 2022, 21:14
                        1
                        • S SGaist
                          2 Mar 2022, 20:33

                          Paint the image before the rectangle.

                          J Offline
                          J Offline
                          john_hobbyist
                          wrote on 2 Mar 2022, 21:14 last edited by john_hobbyist 3 Mar 2022, 12:58
                          #12

                          I have added this command:

                          painter.drawImage(photo)
                          

                          under:

                          painter = QPainter(self)
                          

                          Nothing works...I don't see neither the photo, nor the rectangle... Any idea?

                          1 Reply Last reply
                          0
                          • J Offline
                            J Offline
                            john_hobbyist
                            wrote on 3 Mar 2022, 21:06 last edited by
                            #13

                            I did some other tests, nothing...

                            1 Reply Last reply
                            0
                            • S Offline
                              S Offline
                              SGaist
                              Lifetime Qt Champion
                              wrote on 3 Mar 2022, 21:11 last edited by
                              #14

                              Except that photo is passed only in your __init__ method.

                              Please provide your code rather than lines without context stating that it does not work.

                              Interested in AI ? www.idiap.ch
                              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                              1 Reply Last reply
                              0
                              • J Offline
                                J Offline
                                john_hobbyist
                                wrote on 3 Mar 2022, 21:19 last edited by john_hobbyist 3 Mar 2022, 21:20
                                #15

                                @SGaist Yes, sorry! Here it does not show anything... (source: https://stackoverflow.com/questions/61034583/drawing-a-circle-on-a-qwidget-python-gui and https://codeloop.org/pyqt5-drawing-rectangle-with-qpainter-class/)

                                from PyQt5 import QtGui
                                import sys
                                from PyQt5.QtWidgets import *
                                from PyQt5.QtCore import *
                                from PyQt5.QtGui import *
                                 
                                class Canvas(QWidget): 
                                    def __init__(self, photo, *args, **kwargs): 
                                        super().__init__(*args, **kwargs) 
                                        
                                        self.image = QImage(photo)
                                        self.setFixedSize(self.image.width(), self.image.height())
                                        self.pressed = self.moving = False
                                        self.revisions = []
                                 
                                        self.title = "PyQt5 Drawing Rectangle"
                                        self.top = 100
                                        self.left = 100
                                        self.width = 680
                                        self.height = 500
                                 
                                        self.InitWindow()
                                 
                                    def InitWindow(self):
                                        self.setWindowIcon(QtGui.QIcon("icon.png"))
                                        self.setWindowTitle(self.title)
                                        self.setGeometry(self.top, self.left, self.width, self.height)
                                        self.show()
                                
                                    def paintEvent(self, e):
                                        painter = QPainter(self)
                                        painter.drawImage(photo)
                                        painter.setPen(QPen(Qt.green, 5, Qt.SolidLine))
                                        painter.setBrush(QBrush(Qt.transparent))
                                        painter.drawRect(100, 150, 400,200)
                                
                                class MainWindow(QMainWindow):
                                
                                    def __init__(self):
                                        super().__init__()
                                        w = QWidget()
                                        self.setCentralWidget(w)
                                        canvas = Canvas('image3.png') 
                                        grid = QGridLayout(w)
                                        grid.addWidget(canvas)
                                
                                if __name__ == '__main__':
                                    app = QApplication(sys.argv)
                                    gui = MainWindow()
                                    gui.show()
                                    sys.exit(app.exec_())
                                
                                1 Reply Last reply
                                0
                                • S Offline
                                  S Offline
                                  SGaist
                                  Lifetime Qt Champion
                                  wrote on 3 Mar 2022, 21:23 last edited by
                                  #16

                                  And that code runs without triggering an exception ?
                                  "photo" is unknown in your paintEvent. You should draw "self.image".

                                  Interested in AI ? www.idiap.ch
                                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                  J 1 Reply Last reply 3 Mar 2022, 21:32
                                  0
                                  • S SGaist
                                    3 Mar 2022, 21:23

                                    And that code runs without triggering an exception ?
                                    "photo" is unknown in your paintEvent. You should draw "self.image".

                                    J Offline
                                    J Offline
                                    john_hobbyist
                                    wrote on 3 Mar 2022, 21:32 last edited by
                                    #17

                                    @SGaist If you mean: "painter.drawImage(self.image)" I see neither the image nor the rectangle and many errors...

                                    jsulmJ 1 Reply Last reply 4 Mar 2022, 05:20
                                    0
                                    • J john_hobbyist
                                      3 Mar 2022, 21:32

                                      @SGaist If you mean: "painter.drawImage(self.image)" I see neither the image nor the rectangle and many errors...

                                      jsulmJ Offline
                                      jsulmJ Offline
                                      jsulm
                                      Lifetime Qt Champion
                                      wrote on 4 Mar 2022, 05:20 last edited by
                                      #18

                                      @john_hobbyist said in Draw a rectangle over an image:

                                      many errors

                                      Would be nice if you would let us know what errors...

                                      https://forum.qt.io/topic/113070/qt-code-of-conduct

                                      1 Reply Last reply
                                      0
                                      • J Offline
                                        J Offline
                                        john_hobbyist
                                        wrote on 4 Mar 2022, 07:25 last edited by john_hobbyist 3 Apr 2022, 07:28
                                        #19

                                        @jsulm Yes, of course! The code is this (for source see my previous messages...):

                                        from PyQt5 import QtGui
                                        import sys
                                        from PyQt5.QtWidgets import *
                                        from PyQt5.QtCore import *
                                        from PyQt5.QtGui import *
                                         
                                        class Canvas(QWidget): 
                                            def __init__(self, photo, *args, **kwargs): 
                                                super().__init__(*args, **kwargs) 
                                                
                                                self.image = QImage(photo)
                                                self.setFixedSize(self.image.width(), self.image.height())
                                                self.pressed = self.moving = False
                                                self.revisions = []
                                         
                                                self.title = "PyQt5 Drawing Rectangle"
                                                self.top = 100
                                                self.left = 100
                                                self.width = 680
                                                self.height = 500
                                         
                                                self.InitWindow()
                                         
                                            def InitWindow(self):
                                                self.setWindowIcon(QtGui.QIcon("icon.png"))
                                                self.setWindowTitle(self.title)
                                                self.setGeometry(self.top, self.left, self.width, self.height)
                                                self.show()
                                        
                                            def paintEvent(self, e):
                                                painter = QPainter(self)
                                                painter.drawImage(self.image)
                                                painter.setPen(QPen(Qt.green, 5, Qt.SolidLine))
                                                painter.setBrush(QBrush(Qt.transparent))
                                                painter.drawRect(100, 150, 400,200)
                                        
                                        class MainWindow(QMainWindow):
                                        
                                            def __init__(self):
                                                super().__init__()
                                                w = QWidget()
                                                self.setCentralWidget(w)
                                                canvas = Canvas('image3.png') 
                                                grid = QGridLayout(w)
                                                grid.addWidget(canvas)
                                        
                                        if __name__ == '__main__':
                                            app = QApplication(sys.argv)
                                            gui = MainWindow()
                                            gui.show()
                                            sys.exit(app.exec_())
                                        

                                        The errors are these:

                                        Traceback (most recent call last):
                                          File "draw_fixed_rectangle_with_image.py", line 32, in paintEvent
                                            painter.drawImage(self.image)
                                        TypeError: arguments did not match any overloaded call:
                                          drawImage(self, QRectF, QImage): argument 1 has unexpected type 'QImage'
                                          drawImage(self, QRect, QImage): argument 1 has unexpected type 'QImage'
                                          drawImage(self, Union[QPointF, QPoint], QImage): argument 1 has unexpected type 'QImage'
                                          drawImage(self, QPoint, QImage): argument 1 has unexpected type 'QImage'
                                          drawImage(self, int, int, QImage, sx: int = 0, sy: int = 0, sw: int = -1, sh: int = -1, flags: Union[Qt.ImageConversionFlags, Qt.ImageConversionFlag] = Qt.ImageConversionFlag.AutoColor): argument 1 has unexpected type 'QImage'
                                          drawImage(self, QRectF, QImage, QRectF, flags: Union[Qt.ImageConversionFlags, Qt.ImageConversionFlag] = Qt.ImageConversionFlag.AutoColor): argument 1 has unexpected type 'QImage'
                                          drawImage(self, QRect, QImage, QRect, flags: Union[Qt.ImageConversionFlags, Qt.ImageConversionFlag] = Qt.ImageConversionFlag.AutoColor): argument 1 has unexpected type 'QImage'
                                          drawImage(self, Union[QPointF, QPoint], QImage, QRectF, flags: Union[Qt.ImageConversionFlags, Qt.ImageConversionFlag] = Qt.ImageConversionFlag.AutoColor): argument 1 has unexpected type 'QImage'
                                          drawImage(self, QPoint, QImage, QRect, flags: Union[Qt.ImageConversionFlags, Qt.ImageConversionFlag] = Qt.ImageConversionFlag.AutoColor): argument 1 has unexpected type 'QImage'
                                        QBackingStore::endPaint() called with active painter; did you forget to destroy it or call QPainter::end() on it?
                                        Traceback (most recent call last):
                                          File "draw_fixed_rectangle_with_image.py", line 32, in paintEvent
                                            painter.drawImage(self.image)
                                        TypeError: arguments did not match any overloaded call:
                                          drawImage(self, QRectF, QImage): argument 1 has unexpected type 'QImage'
                                          drawImage(self, QRect, QImage): argument 1 has unexpected type 'QImage'
                                          drawImage(self, Union[QPointF, QPoint], QImage): argument 1 has unexpected type 'QImage'
                                          drawImage(self, QPoint, QImage): argument 1 has unexpected type 'QImage'
                                          drawImage(self, int, int, QImage, sx: int = 0, sy: int = 0, sw: int = -1, sh: int = -1, flags: Union[Qt.ImageConversionFlags, Qt.ImageConversionFlag] = Qt.ImageConversionFlag.AutoColor): argument 1 has unexpected type 'QImage'
                                          drawImage(self, QRectF, QImage, QRectF, flags: Union[Qt.ImageConversionFlags, Qt.ImageConversionFlag] = Qt.ImageConversionFlag.AutoColor): argument 1 has unexpected type 'QImage'
                                          drawImage(self, QRect, QImage, QRect, flags: Union[Qt.ImageConversionFlags, Qt.ImageConversionFlag] = Qt.ImageConversionFlag.AutoColor): argument 1 has unexpected type 'QImage'
                                          drawImage(self, Union[QPointF, QPoint], QImage, QRectF, flags: Union[Qt.ImageConversionFlags, Qt.ImageConversionFlag] = Qt.ImageConversionFlag.AutoColor): argument 1 has unexpected type 'QImage'
                                          drawImage(self, QPoint, QImage, QRect, flags: Union[Qt.ImageConversionFlags, Qt.ImageConversionFlag] = Qt.ImageConversionFlag.AutoColor): argument 1 has unexpected type 'QImage'
                                        Traceback (most recent call last):
                                          File "draw_fixed_rectangle_with_image.py", line 32, in paintEvent
                                            painter.drawImage(self.image)
                                        TypeError: arguments did not match any overloaded call:
                                          drawImage(self, QRectF, QImage): argument 1 has unexpected type 'QImage'
                                          drawImage(self, QRect, QImage): argument 1 has unexpected type 'QImage'
                                          drawImage(self, Union[QPointF, QPoint], QImage): argument 1 has unexpected type 'QImage'
                                          drawImage(self, QPoint, QImage): argument 1 has unexpected type 'QImage'
                                          drawImage(self, int, int, QImage, sx: int = 0, sy: int = 0, sw: int = -1, sh: int = -1, flags: Union[Qt.ImageConversionFlags, Qt.ImageConversionFlag] = Qt.ImageConversionFlag.AutoColor): argument 1 has unexpected type 'QImage'
                                          drawImage(self, QRectF, QImage, QRectF, flags: Union[Qt.ImageConversionFlags, Qt.ImageConversionFlag] = Qt.ImageConversionFlag.AutoColor): argument 1 has unexpected type 'QImage'
                                          drawImage(self, QRect, QImage, QRect, flags: Union[Qt.ImageConversionFlags, Qt.ImageConversionFlag] = Qt.ImageConversionFlag.AutoColor): argument 1 has unexpected type 'QImage'
                                          drawImage(self, Union[QPointF, QPoint], QImage, QRectF, flags: Union[Qt.ImageConversionFlags, Qt.ImageConversionFlag] = Qt.ImageConversionFlag.AutoColor): argument 1 has unexpected type 'QImage'
                                          drawImage(self, QPoint, QImage, QRect, flags: Union[Qt.ImageConversionFlags, Qt.ImageConversionFlag] = Qt.ImageConversionFlag.AutoColor): argument 1 has unexpected type 'QImage'
                                        QBackingStore::endPaint() called with active painter; did you forget to destroy it or call QPainter::end() on it?
                                        QPaintDevice: Cannot destroy paint device that is being painted
                                        
                                        
                                        jsulmJ 1 Reply Last reply 4 Mar 2022, 07:30
                                        0
                                        • J john_hobbyist
                                          4 Mar 2022, 07:25

                                          @jsulm Yes, of course! The code is this (for source see my previous messages...):

                                          from PyQt5 import QtGui
                                          import sys
                                          from PyQt5.QtWidgets import *
                                          from PyQt5.QtCore import *
                                          from PyQt5.QtGui import *
                                           
                                          class Canvas(QWidget): 
                                              def __init__(self, photo, *args, **kwargs): 
                                                  super().__init__(*args, **kwargs) 
                                                  
                                                  self.image = QImage(photo)
                                                  self.setFixedSize(self.image.width(), self.image.height())
                                                  self.pressed = self.moving = False
                                                  self.revisions = []
                                           
                                                  self.title = "PyQt5 Drawing Rectangle"
                                                  self.top = 100
                                                  self.left = 100
                                                  self.width = 680
                                                  self.height = 500
                                           
                                                  self.InitWindow()
                                           
                                              def InitWindow(self):
                                                  self.setWindowIcon(QtGui.QIcon("icon.png"))
                                                  self.setWindowTitle(self.title)
                                                  self.setGeometry(self.top, self.left, self.width, self.height)
                                                  self.show()
                                          
                                              def paintEvent(self, e):
                                                  painter = QPainter(self)
                                                  painter.drawImage(self.image)
                                                  painter.setPen(QPen(Qt.green, 5, Qt.SolidLine))
                                                  painter.setBrush(QBrush(Qt.transparent))
                                                  painter.drawRect(100, 150, 400,200)
                                          
                                          class MainWindow(QMainWindow):
                                          
                                              def __init__(self):
                                                  super().__init__()
                                                  w = QWidget()
                                                  self.setCentralWidget(w)
                                                  canvas = Canvas('image3.png') 
                                                  grid = QGridLayout(w)
                                                  grid.addWidget(canvas)
                                          
                                          if __name__ == '__main__':
                                              app = QApplication(sys.argv)
                                              gui = MainWindow()
                                              gui.show()
                                              sys.exit(app.exec_())
                                          

                                          The errors are these:

                                          Traceback (most recent call last):
                                            File "draw_fixed_rectangle_with_image.py", line 32, in paintEvent
                                              painter.drawImage(self.image)
                                          TypeError: arguments did not match any overloaded call:
                                            drawImage(self, QRectF, QImage): argument 1 has unexpected type 'QImage'
                                            drawImage(self, QRect, QImage): argument 1 has unexpected type 'QImage'
                                            drawImage(self, Union[QPointF, QPoint], QImage): argument 1 has unexpected type 'QImage'
                                            drawImage(self, QPoint, QImage): argument 1 has unexpected type 'QImage'
                                            drawImage(self, int, int, QImage, sx: int = 0, sy: int = 0, sw: int = -1, sh: int = -1, flags: Union[Qt.ImageConversionFlags, Qt.ImageConversionFlag] = Qt.ImageConversionFlag.AutoColor): argument 1 has unexpected type 'QImage'
                                            drawImage(self, QRectF, QImage, QRectF, flags: Union[Qt.ImageConversionFlags, Qt.ImageConversionFlag] = Qt.ImageConversionFlag.AutoColor): argument 1 has unexpected type 'QImage'
                                            drawImage(self, QRect, QImage, QRect, flags: Union[Qt.ImageConversionFlags, Qt.ImageConversionFlag] = Qt.ImageConversionFlag.AutoColor): argument 1 has unexpected type 'QImage'
                                            drawImage(self, Union[QPointF, QPoint], QImage, QRectF, flags: Union[Qt.ImageConversionFlags, Qt.ImageConversionFlag] = Qt.ImageConversionFlag.AutoColor): argument 1 has unexpected type 'QImage'
                                            drawImage(self, QPoint, QImage, QRect, flags: Union[Qt.ImageConversionFlags, Qt.ImageConversionFlag] = Qt.ImageConversionFlag.AutoColor): argument 1 has unexpected type 'QImage'
                                          QBackingStore::endPaint() called with active painter; did you forget to destroy it or call QPainter::end() on it?
                                          Traceback (most recent call last):
                                            File "draw_fixed_rectangle_with_image.py", line 32, in paintEvent
                                              painter.drawImage(self.image)
                                          TypeError: arguments did not match any overloaded call:
                                            drawImage(self, QRectF, QImage): argument 1 has unexpected type 'QImage'
                                            drawImage(self, QRect, QImage): argument 1 has unexpected type 'QImage'
                                            drawImage(self, Union[QPointF, QPoint], QImage): argument 1 has unexpected type 'QImage'
                                            drawImage(self, QPoint, QImage): argument 1 has unexpected type 'QImage'
                                            drawImage(self, int, int, QImage, sx: int = 0, sy: int = 0, sw: int = -1, sh: int = -1, flags: Union[Qt.ImageConversionFlags, Qt.ImageConversionFlag] = Qt.ImageConversionFlag.AutoColor): argument 1 has unexpected type 'QImage'
                                            drawImage(self, QRectF, QImage, QRectF, flags: Union[Qt.ImageConversionFlags, Qt.ImageConversionFlag] = Qt.ImageConversionFlag.AutoColor): argument 1 has unexpected type 'QImage'
                                            drawImage(self, QRect, QImage, QRect, flags: Union[Qt.ImageConversionFlags, Qt.ImageConversionFlag] = Qt.ImageConversionFlag.AutoColor): argument 1 has unexpected type 'QImage'
                                            drawImage(self, Union[QPointF, QPoint], QImage, QRectF, flags: Union[Qt.ImageConversionFlags, Qt.ImageConversionFlag] = Qt.ImageConversionFlag.AutoColor): argument 1 has unexpected type 'QImage'
                                            drawImage(self, QPoint, QImage, QRect, flags: Union[Qt.ImageConversionFlags, Qt.ImageConversionFlag] = Qt.ImageConversionFlag.AutoColor): argument 1 has unexpected type 'QImage'
                                          Traceback (most recent call last):
                                            File "draw_fixed_rectangle_with_image.py", line 32, in paintEvent
                                              painter.drawImage(self.image)
                                          TypeError: arguments did not match any overloaded call:
                                            drawImage(self, QRectF, QImage): argument 1 has unexpected type 'QImage'
                                            drawImage(self, QRect, QImage): argument 1 has unexpected type 'QImage'
                                            drawImage(self, Union[QPointF, QPoint], QImage): argument 1 has unexpected type 'QImage'
                                            drawImage(self, QPoint, QImage): argument 1 has unexpected type 'QImage'
                                            drawImage(self, int, int, QImage, sx: int = 0, sy: int = 0, sw: int = -1, sh: int = -1, flags: Union[Qt.ImageConversionFlags, Qt.ImageConversionFlag] = Qt.ImageConversionFlag.AutoColor): argument 1 has unexpected type 'QImage'
                                            drawImage(self, QRectF, QImage, QRectF, flags: Union[Qt.ImageConversionFlags, Qt.ImageConversionFlag] = Qt.ImageConversionFlag.AutoColor): argument 1 has unexpected type 'QImage'
                                            drawImage(self, QRect, QImage, QRect, flags: Union[Qt.ImageConversionFlags, Qt.ImageConversionFlag] = Qt.ImageConversionFlag.AutoColor): argument 1 has unexpected type 'QImage'
                                            drawImage(self, Union[QPointF, QPoint], QImage, QRectF, flags: Union[Qt.ImageConversionFlags, Qt.ImageConversionFlag] = Qt.ImageConversionFlag.AutoColor): argument 1 has unexpected type 'QImage'
                                            drawImage(self, QPoint, QImage, QRect, flags: Union[Qt.ImageConversionFlags, Qt.ImageConversionFlag] = Qt.ImageConversionFlag.AutoColor): argument 1 has unexpected type 'QImage'
                                          QBackingStore::endPaint() called with active painter; did you forget to destroy it or call QPainter::end() on it?
                                          QPaintDevice: Cannot destroy paint device that is being painted
                                          
                                          
                                          jsulmJ Offline
                                          jsulmJ Offline
                                          jsulm
                                          Lifetime Qt Champion
                                          wrote on 4 Mar 2022, 07:30 last edited by jsulm 3 Apr 2022, 07:30
                                          #20

                                          @john_hobbyist Please take a look at documentation: https://doc.qt.io/qt-5/qpainter.html
                                          What are drawImage() parameters? And what do you pass to it? It is quite apparent what you are doing wrong even from the error message itself:

                                          drawImage(self, QRectF, QImage): argument 1 has unexpected type 'QImage'
                                          

                                          https://forum.qt.io/topic/113070/qt-code-of-conduct

                                          1 Reply Last reply
                                          2

                                          3/27

                                          1 Mar 2022, 11:21

                                          24 unread
                                          • Login

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