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. Combine several images into one?
Qt 6.11 is out! See what's new in the release blog

Combine several images into one?

Scheduled Pinned Locked Moved Unsolved Qt for Python
2 Posts 2 Posters 857 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.
  • P Offline
    P Offline
    pmeloy
    wrote on last edited by
    #1

    I've been using PyQt5 for just a few days but I'm doing pretty well except for one thing I just can't figure out.

    I have three images (parts of a whole) that I want to combine into one. I tried various things but messed up every time. The most promising looks like QPainter but I can't seem to figure out the arguments and I can't find any simple examples online anywhere.

    Anyway, I have three images but to start I'm trying with just one like this:

    		for part in self.parts:
    			_width += part.width()
    		
    		_img = QPixmap(_width,self.SrcImg.height())
    

    So the target image is full size of the three combined. To start I'm only trying to get one image painted onto it but that's failing miserably no matter what I try. Here's what I thought it should look like after reading the docs

    		painter = QPainter(_img)
    		painter.setCompositionMode(QPainter.CompositionMode_SourceAtop)		
    		painter.drawImage(0,0,self.parts[0])
    

    But that gives an error:
    painter.drawImage(0,0,self.parts[0])
    TypeError: arguments did not match any overloaded call:
    drawImage(self, QRectF, QImage): argument 1 has unexpected type 'int'
    drawImage(self, QRect, QImage): argument 1 has unexpected type 'int'

    So I tried making a QRect(0,0,self.parts[0].width,self.parts[0].height()) but then the error just changes from type int to type QRect

    It looks really simple but I'm just not getting it for some reason

    jsulmJ 1 Reply Last reply
    0
    • P pmeloy

      I've been using PyQt5 for just a few days but I'm doing pretty well except for one thing I just can't figure out.

      I have three images (parts of a whole) that I want to combine into one. I tried various things but messed up every time. The most promising looks like QPainter but I can't seem to figure out the arguments and I can't find any simple examples online anywhere.

      Anyway, I have three images but to start I'm trying with just one like this:

      		for part in self.parts:
      			_width += part.width()
      		
      		_img = QPixmap(_width,self.SrcImg.height())
      

      So the target image is full size of the three combined. To start I'm only trying to get one image painted onto it but that's failing miserably no matter what I try. Here's what I thought it should look like after reading the docs

      		painter = QPainter(_img)
      		painter.setCompositionMode(QPainter.CompositionMode_SourceAtop)		
      		painter.drawImage(0,0,self.parts[0])
      

      But that gives an error:
      painter.drawImage(0,0,self.parts[0])
      TypeError: arguments did not match any overloaded call:
      drawImage(self, QRectF, QImage): argument 1 has unexpected type 'int'
      drawImage(self, QRect, QImage): argument 1 has unexpected type 'int'

      So I tried making a QRect(0,0,self.parts[0].width,self.parts[0].height()) but then the error just changes from type int to type QRect

      It looks really simple but I'm just not getting it for some reason

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @pmeloy said in Combine several images into one?:

      QRect(0,0,self.parts[0].width,self.parts[0].height())

      Please take a closer look at that line: it is quite apparent what is wrong here (hint: self.parts[0].width).

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

      1 Reply Last reply
      2

      • Login

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