def pixelLength(self, direction): """Return the length of one pixel in the direction indicated (in local coordinates)""" dt = self.deviceTransform() if dt is None: return None viewDir = Point(dt.map(direction) - dt.map(Point(0,0))) norm = viewDir.norm() dti = dt.inverted()[0] return Point(dti.map(norm)-dti.map(Point(0,0))).length()
def pixelLength(self, direction): """Return the length of one pixel in the direction indicated (in local coordinates)""" dt = self.deviceTransform() if dt is None: return None viewDir = Point(dt.map(direction) - dt.map(Point(0, 0))) norm = viewDir.norm() dti = dt.inverted()[0] return Point(dti.map(norm) - dti.map(Point(0, 0))).length()
def boundingRect(self): br = UIGraphicsItem.boundingRect(self) ## add a 4-pixel radius around the line for mouse interaction. #print "line bounds:", self, br dt = self.deviceTransform() if dt is None: return QtCore.QRectF() lineDir = Point(dt.map(Point(1, 0)) - dt.map(Point(0,0))) ## direction of line in pixel-space orthoDir = Point(lineDir[1], -lineDir[0]) ## orthogonal to line in pixel-space try: norm = orthoDir.norm() ## direction of one pixel orthogonal to line except ZeroDivisionError: return br dti = dt.inverted()[0] px = Point(dti.map(norm)-dti.map(Point(0,0))) ## orthogonal pixel mapped back to item coords px = px[1] ## project to y-direction br.setBottom(-px*4) br.setTop(px*4) return br.normalized()