我在一个QPixmap
对象中有一个QLabel
对象。我想在像素图矩形中绘制,以便我可以获得图像中该矩形的坐标。我的问题是,当我在该像素图中绘制那个 qrubberband 矩形时,它没有得到图像的原始坐标。它正在吸引其他人,我不知道为什么。这是我创建 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())
提前谢谢你。