Saturday, February 13, 2010

Setting rectangle to choose crop area

def mousePressEvent(self, event):
        self.rbOrigin = self.mapFromGlobal(event.globalPos())
        self.rubberBand.setGeometry(QtCore.QRect(self.rbOrigin, QtCore.QSize()))
        self.rubberBand.show()
        self.x1 = int(QtCore.QPoint.x(self.rbOrigin))
        self.y1 = int(QtCore.QPoint.y(self.rbOrigin))
        print self.x1
        print self.y1

def mouseMoveEvent ( self, event ) :
        self.x2 = int(QtCore.QPoint.x(self.mapFromGlobal(event.globalPos())))
        self.y2 = int(QtCore.QPoint.y(self.mapFromGlobal(event.globalPos())))
        self.x = self.x2 - self.x1
        self.y = self.y2 - self.y1
       
        if (self.x == 0):
            self.x = 4*self.y
        else:
            self.y = self.x/4
        self.x2 = self.x + self.x1
        self.y2 = self.y + self.y1
               
        self.rubberBand.setGeometry(QtCore.QRect(QtCore.QPoint(self.x1, self.y1), QtCore.QPoint(self.x2, self.y2)).normalized())
       

No comments:

Post a Comment