Question: I write this code to move image to another place but when I moving the image each point create new box so I get like this view: Image box duplicate each moving step. But I cant find the solution for this.  import sys from PyQt5.QtCore import QRect from PyQt5.QtGui import QPixmap, QPainter, QPen, QColor from PyQt5.QtWidgets import * from test import Ui_MainWindow from PyQt5.QtCore import Qt, QRect, QPoint class MainWindow(QMainWindow): def __init__(self,parent = None): QMainWindow.__init__(self) self.ui = Ui_MainWindow() self.ui.setupUi(self) self.boxes = [] # Klonlanmış box'ların listesi self.original_box = QPixmap("box.png").scaled(100, 150) # Orjinal box resmi self.original_palette = QPixmap("palette.png") # print( self.img.width(),self.img.height()) self.ui.image.setPixmap(self.original_box) self.ui.palet.setPixmap(self.original_palette) self.dragging = False # Sürükleme durumu self.offset = None # Sürükleme konumu self.ui.image.setFixedSize(self.original_box.width(), self.original_box.height()) self.ui.palet.setFixedSize(self.original_palette.width(), self.original_palette.height()) # self.ui.image.setScaledContents(True) self.ui.image.setContentsMargins(0, 0, 0, 0) self.ui.image.setStyleSheet("QLabel { padding: 0px; }") self.ui.palet.setContentsMargins(0, 0, 0, 0) self.ui.palet.setStyleSheet("QLabel { padding: 0px; }") print("After") self.ui.widget_2.setAcceptDrops(True) # Bırakma işlemini kabul et self.last_offset = None def paintEvent(self, event): self.painterInstance = QPainter(self.original_palette) # set rectangle color and thickness self.penRectangle = QPen(Qt.red) self.penRectangle.setWidth(3) # draw rectangle on painter self.painterInstance.setPen(self.penRectangle) # Sürüklenen box'ı çiz if self.dragging : # if self.last_offset != None: # self.painterInstance.setCompositionMode(QPainter.CompositionMode_Source) # self.painterInstance.fillRect(QRect(self.offset, self.original_box.size()), Qt.transparent) # self.painterInstance.fillRect(QRect(self.last_offset, self.original_box.size()), Qt.transparent) # self.painterInstance.eraseRect(QRect(int(self.last_offset.x() - self.original_box.width() / 2), # int(self.last_offset.y() - self.original_box.height() / 2), # self.original_box.width(), self.original_box.height())) # # self.painterInstance.setCompositionMode(QPainter.CompositionMode_Source) # self.painterInstance.fillRect(QRect(self.last_offset, self.original_box.size()), Qt.transparent) # print(self.dragging) # painter.drawPixmap(int(self.offset.x() - self.original_box.width() / 2), # int(self.offset.y() - self.original_box.height() / 2), # self.original_box) # self.painterInstance.drawRect(500, 360, 50, 50) self.painterInstance.drawPixmap(int(self.offset.x() - self.original_box.width() / 2), int(self.offset.y() - self.original_box.height() / 2), self.original_box) self.last_offset = self.offset # set pixmap onto the label widget self.ui.palet.setPixmap(self.original_palette) # self.ui.image.setPixmap(self.original_box) # self.relase = False # self.dragging = False # Klonlanmış box'ları çiz # for box in self.boxes: # self.painterInstance.drawPixmap(box.topLeft(), self.original_box) def mousePressEvent(self, event): if event.button() == Qt.LeftButton: print(event.pos()) # print("MAUSE GLOBAL POS",self.ui.image.mapFromGlobal(event.globalPos())) # print(self.ui.image.rect().contains(self.ui.image.mapFromGlobal(event.globalPos()))) print(self.ui.widget_2.rect()) if(self.ui.image.rect().contains(self.ui.image.mapFromGlobal(event.globalPos()))): self.dragging = True self.offset = event.pos() print("Offset point", self.offset) def mouseMoveEvent(self, event): if self.dragging: # print("DRAGGING") # Sürüklenen box'ın merkezini güncelle self.offset = event.pos() self.update() def mouseReleaseEvent(self, event): if event.button() == Qt.LeftButton and self.dragging: self.dragging = False print("RELEASE") self.relase = True # Yeni box'ı oluştur new_box = QRect(int(self.offset.x() - self.original_box.width() / 2), int(self.offset.y() - self.original_box.height() / 2), self.original_box.width(), self.original_box.height()) # self.ui.palet.setPixmap(self.original_palette) # self.ui.palet.show() self.boxes.append(new_box) self.update() if __name__ == "__main__": app = QApplication(sys.argv) window = MainWindow() window.show() sys.exit(app.exec_())  I try this in paint method: def paintEvent(self, event): self.painterInstance = QPainter(self.original_palette) # set rectangle color and thickness self.penRectangle = QPen(Qt.red) self.penRectangle.setWidth(3) # draw rectangle on painter self.painterInstance.setPen(self.penRectangle) # Sürüklenen box'ı çiz if self.dragging : if self.last_offset != None: self.painterInstance.eraseRect(QRect(int(self.last_offset.x() - self.original_box.width() / 2), int(self.last_offset.y() - self.original_box.height() / 2), self.original_box.width(), self.original_box.height())) # # self.painterInstance.setCompositionMode(QPainter.CompositionMode_Source) # self.painterInstance.fillRect(QRect(self.last_offset, self.original_box.size()), Qt.transparent) # print(self.dragging) # painter.drawPixmap(int(self.offset.x() - self.original_box.width() / 2), # int(self.offset.y() - self.original_box.height() / 2), # self.original_box) # self.painterInstance.drawRect(500, 360, 50, 50) self.painterInstance.drawPixmap(int(self.offset.x() - self.original_box.width() / 2), int(self.offset.y() - self.original_box.height() / 2), self.original_box) self.last_offset = self.offset # set pixmap onto the label widget  I get this result, erase the background.  How can I solve this problem. I almost close the solution but I cant do the draw related place. EDIT - 2: By the way if I use the region as a mainwindow like this this code move the object with It creates, destroys and re-creates the object at each step. But I can't do this on a layer, actually I should be able to do it.:  import sys from PyQt5.QtWidgets import QApplication, QWidget from PyQt5.QtGui import QPainter, QColor, QPixmap from PyQt5.QtCore import Qt, QRect, QPoint class Rectangle(QWidget): def __init__(self): super().__init__() self.setWindowTitle('Klonlanabilir Boxlar') self.setGeometry(100, 100, 600, 400) self.boxes = [] # Klonlanmış box'ların listesi self.original_box = QPixmap("box.png").scaled(300, 400) # Orjinal box resmi self.dragging = False # Sürükleme durumu self.offset = None # Sürükleme konumu def paintEvent(self, event): painter = QPainter(self) # Orjinal box'ı çiz painter.drawPixmap(100, 100, self.original_box) # Sürüklenen box'ı çiz if self.dragging: painter.drawPixmap(self.offset.x() - self.original_box.width() / 2, self.offset.y() - self.original_box.height() / 2, self.original_box) # Klonlanmış box'ları çiz for box in self.boxes: painter.drawPixmap(box.topLeft(), self.original_box) def mousePressEvent(self, event): if event.button() == Qt.LeftButton: if QRect(100, 150, self.original_box.width(), self.original_box.height()).contains(event.pos()): self.dragging = True self.offset = event.pos() print("Offset point",self.offset) def mouseMoveEvent(self, event): if self.dragging: # Sürüklenen box'ın merkezini güncelle self.offset = event.pos() self.update() def mouseReleaseEvent(self, event): if event.button() == Qt.LeftButton and self.dragging: self.dragging = False # Yeni box'ı oluştur new_box = QRect(self.offset.x() - self.original_box.width() / 2, self.offset.y() - self.original_box.height() / 2, self.original_box.width(), self.original_box.height()) self.boxes.append(new_box) self.update() if __name__ == '__main__': app = QApplication(sys.argv) window = Rectangle() window.show() sys.exit(app.exec_()) 

Answer: I solved my problem with this code: import sys from PyQt5.QtCore import QRect from PyQt5.QtGui import QPixmap, QPainter, QPen, QColor from PyQt5.QtWidgets import * from test import Ui_MainWindow from PyQt5.QtCore import Qt, QRect, QPoint class MainWindow(QMainWindow): def __init__(self,parent = None): QMainWindow.__init__(self) self.ui = Ui_MainWindow() self.ui.setupUi(self) self.boxes = [] # Klonlanmış box'ların listesi self.original_box = QPixmap("box.png").scaled(100, 150) # Orjinal box resmi self.original_palette = QPixmap("palette.png") # print( self.img.width(),self.img.height()) self.ui.image.setPixmap(self.original_box) self.ui.palet.setPixmap(self.original_palette) self.dragging = False # Sürükleme durumu self.offset = None # Sürükleme konumu self.ui.image.setFixedSize(self.original_box.width(), self.original_box.height()) self.ui.palet.setFixedSize(self.original_palette.width(), self.original_palette.height()) # self.ui.image.setScaledContents(True) self.ui.image.setContentsMargins(0, 0, 0, 0) self.ui.image.setStyleSheet("QLabel { padding: 0px; }") # self.ui.palet.setContentsMargins(0, 0, 0, 0) # self.ui.palet.setStyleSheet("QLabel { padding: 0px; }") print("After") self.ui.widget_2.setAcceptDrops(True) # Bırakma işlemini kabul et self.firstMove = False self.last_offset = None def paintEvent(self, event): self.ui.palet.setPixmap(self.original_palette) painter = QPainter(self.ui.palet.pixmap()) if self.dragging : # self.ui.palet.setPixmap(self.original_palette) painter.drawPixmap(int(self.offset.x() - self.original_box.width() / 2), int(self.offset.y() - self.original_box.height() / 2), self.original_box) for box in self.boxes: painter.drawPixmap(box.topLeft(), self.original_box) def mousePressEvent(self, event): if event.button() == Qt.LeftButton: print(event.pos()) # print("MAUSE GLOBAL POS",self.ui.image.mapFromGlobal(event.globalPos())) # print(self.ui.image.rect().contains(self.ui.image.mapFromGlobal(event.globalPos()))) if(self.ui.image.rect().contains(self.ui.image.mapFromGlobal(event.globalPos()))): self.dragging = True self.offset = event.pos() self.firstMove = True print("Offset point", self.offset) def mouseMoveEvent(self, event): if self.dragging: # print("DRAGGING") print(self.ui.image.mapFromGlobal(event.globalPos())) # Sürüklenen box'ın merkezini güncelle self.offset = event.pos() self.update() def mouseReleaseEvent(self, event): if event.button() == Qt.LeftButton and self.dragging: self.dragging = False print("RELEASE") self.relase = True # Yeni box'ı oluştur new_box = QRect(int(self.offset.x() - self.original_box.width() / 2), int(self.offset.y() - self.original_box.height() / 2), self.original_box.width(), self.original_box.height()) # self.ui.palet.setPixmap(self.original_palette) # self.ui.palet.show() self.boxes.append(new_box) self.update() self.boxes[-1].moveCenter(self.offset) if __name__ == "__main__": app = QApplication(sys.argv) window = MainWindow() window.show() sys.exit(app.exec_())  This part solved my problem:  def paintEvent(self, event): self.ui.palet.setPixmap(self.original_palette) painter = QPainter(self.ui.palet.pixmap()) if self.dragging : # self.ui.palet.setPixmap(self.original_palette) painter.drawPixmap(int(self.offset.x() - self.original_box.width() / 2), int(self.offset.y() - self.original_box.height() / 2), self.original_box) for box in self.boxes: painter.drawPixmap(box.topLeft(), self.original_box)  I can drag and drop into this palet image:  But I have little problem here, when I click the box it detects but this create on here:  I think I have problem with event.pos() how can I solve this ?