def __init__(self, tree_node, parent=None, **kwargs): self.tree_node = tree_node super().__init__(self._get_rect_attributes(), parent) self.tree_node.graphics_item = self self.setTransformOriginPoint(self.boundingRect().center()) self.setRotation(degrees(self.tree_node.square.angle)) self.setBrush(kwargs.get('brush', QColor('#297A1F'))) # The border should be invariant to scaling pen = QPen(QColor(Qt.black)) pen.setWidthF(0.75) pen.setCosmetic(True) self.setPen(pen) self.setAcceptHoverEvents(True) self.setZValue(kwargs.get('zvalue', 0)) self.z_step = Z_STEP # calculate the correct z values based on the parent if self.tree_node.parent != TreeAdapter.ROOT_PARENT: p = self.tree_node.parent # override root z step num_children = len(p.children) own_index = [ 1 if c.label == self.tree_node.label else 0 for c in p.children ].index(1) self.z_step = int(p.graphics_item.z_step / num_children) base_z = p.graphics_item.zValue() self.setZValue(base_z + own_index * self.z_step)
def __init__(self, tree_node, parent=None, **kwargs): self.tree_node = tree_node super().__init__(self._get_rect_attributes(), parent) self.tree_node.graphics_item = self self.setTransformOriginPoint(self.boundingRect().center()) self.setRotation(degrees(self.tree_node.square.angle)) self.setBrush(kwargs.get('brush', QColor('#297A1F'))) # The border should be invariant to scaling pen = QPen(QColor(Qt.black)) pen.setWidthF(0.75) pen.setCosmetic(True) self.setPen(pen) self.setAcceptHoverEvents(True) self.setZValue(kwargs.get('zvalue', 0)) self.z_step = Z_STEP # calculate the correct z values based on the parent if self.tree_node.parent != TreeAdapter.ROOT_PARENT: p = self.tree_node.parent # override root z step num_children = len(p.children) own_index = [1 if c.label == self.tree_node.label else 0 for c in p.children].index(1) self.z_step = int(p.graphics_item.z_step / num_children) base_z = p.graphics_item.zValue() self.setZValue(base_z + own_index * self.z_step)
def shape(self): if self.__shape is None: path = self.curvePath() pen = QPen(self.pen()) pen.setWidthF(max(pen.widthF(), 7.0)) pen.setStyle(Qt.SolidLine) self.__shape = stroke_path(path, pen) return self.__shape
def crosshairs(color, radius=24, circle=False): radius = max(radius, 16) pixmap = QPixmap(radius, radius) pixmap.fill(Qt.transparent) painter = QPainter() painter.begin(pixmap) painter.setRenderHints(QPainter.Antialiasing) pen = QPen(QBrush(color), 1) pen.setWidthF(1.5) painter.setPen(pen) if circle: painter.drawEllipse(2, 2, radius - 2, radius - 2) painter.drawLine(radius / 2, 7, radius / 2, radius / 2 - 7) painter.drawLine(7, radius / 2, radius / 2 - 7, radius / 2) painter.end() return pixmap
def __updateStyleState(self): """ Update the arrows' brush, pen, ... based on it's state """ if self.isSelected(): color = self.__color.darker(150) pen = QPen(QColor(96, 158, 215), Qt.DashDotLine) pen.setWidthF(1.25) pen.setCosmetic(True) self.__shadow.setColor(pen.color().darker(150)) else: color = self.__color pen = QPen(Qt.NoPen) self.__shadow.setColor(QColor(63, 63, 63, 180)) self.__arrowItem.setBrush(color) self.__arrowItem.setPen(pen)
def paint(self, painter, option, widget=None): # Override the default selected appearance if self.isSelected(): option.state ^= QStyle.State_Selected rect = self.rect() # this must render before overlay due to order in which it's drawn super().paint(painter, option, widget) painter.save() pen = QPen(QColor(Qt.black)) pen.setWidthF(2) pen.setCosmetic(True) pen.setJoinStyle(Qt.MiterJoin) painter.setPen(pen) painter.drawRect(rect) painter.restore() else: super().paint(painter, option, widget)
def hoverEnterEvent(self, event): pen = QPen(self.pen()) pen.setWidthF(3) self.setPen(pen) return RugItem.hoverEnterEvent(self, event)