コード例 #1
0
    def boundingRect(self):
        anchor = self.mapFromParent(self._chart.mapToPosition(self._anchor))
        rect = QRectF()
        rect.setLeft(min(self._rect.left(), anchor.x()))
        rect.setRight(max(self._rect.right(), anchor.x()))
        rect.setTop(min(self._rect.top(), anchor.y()))
        rect.setBottom(max(self._rect.bottom(), anchor.y()))

        return rect
コード例 #2
0
    def drag_rect(self, pos):
        # Calculate how much the mouse has moved since the click.
        x_diff = pos.x() - self.mouse_press_pos.x()
        y_diff = pos.y() - self.mouse_press_pos.y()

        # Start with the rectangle as it was when clicked.
        rect = QRectF(self.mouse_press_rect)

        # Then adjust by the distance the mouse moved.
        if self.selected_handle is None:
            rect.translate(x_diff, y_diff)
        elif self.selected_handle == self.HANDLE_TOP_LEFT:
            rect.adjust(x_diff, y_diff, 0, 0)
        elif self.selected_handle == self.HANDLE_TOP:
            rect.setTop(rect.top() + y_diff)
        elif self.selected_handle == self.HANDLE_TOP_RIGHT:
            rect.setTop(rect.top() + y_diff)
            rect.setRight(rect.right() + x_diff)
        elif self.selected_handle == self.HANDLE_LEFT:
            rect.setLeft(rect.left() + x_diff)
        elif self.selected_handle == self.HANDLE_RIGHT:
            rect.setRight(rect.right() + x_diff)
        elif self.selected_handle == self.HANDLE_BOTTOM_LEFT:
            rect.setBottom(rect.bottom() + y_diff)
            rect.setLeft(rect.left() + x_diff)
        elif self.selected_handle == self.HANDLE_BOTTOM:
            rect.setBottom(rect.bottom() + y_diff)
        elif self.selected_handle == self.HANDLE_BOTTOM_RIGHT:
            rect.setBottom(rect.bottom() + y_diff)
            rect.setRight(rect.right() + x_diff)
        return rect