I have a QPixmap
object in a QLabel
object. I want to draw in that pixmap rectangles so that i can get the coordinates of that rectangle in the image. My problem is that when I draw that qrubberband rectangle in that pixmap, it is not getting the original coordinates of the image. It is getting others and I dont know why. Here is my code where I create my qrubberband.
def mousePressEvent (self, eventQMouseEvent):
if eventQMouseEvent.buttons() == Qt.LeftButton:
self.originQPoint = eventQMouseEvent.pos()
self.currentQRubberBand = QRubberBand(QRubberBand.Rectangle, self)
self.sequence.append(self.currentQRubberBand)
r = randint(0, 255)
g = randint(0, 255)
b = randint(0, 255)
palette = QPalette()
palette.setColor(self.currentQRubberBand.foregroundRole(), QColor(r, g, b))
self.currentQRubberBand.setPalette(palette)
self.currentQRubberBand.setGeometry(QRect(self.originQPoint, QSize()))
self.currentQRubberBand.show()
elif eventQMouseEvent.buttons() == Qt.RightButton:
found = False
for rect in self.sequence:
if(rect.geometry().contains(eventQMouseEvent.pos())):
self.menu = MenuRectangle(self._timeline, eventQMouseEvent, rect,
self.imageLabel, self.sequence)
found = True
if not found:
self.menuglobalimage = MenuGlobalImage(self._timeline, eventQMouseEvent, self._topic,
self.sequence, self.imageLabel, self.stamp)
def mouseMoveEvent (self, eventQMouseEvent):
self.currentQRubberBand.setGeometry(QRect(self.originQPoint, eventQMouseEvent.pos()).normalized())
Thank you in advanced.