示例#1
0
    def paint(self, painter, option, widget=None):
        """
        Public method to paint the item in local coordinates.
        
        @param painter reference to the painter object (QPainter)
        @param option style options (QStyleOptionGraphicsItem)
        @param widget optional reference to the widget painted on (QWidget)
        """
        pen = self.pen()
        if (option.state & QStyle.State_Selected) == \
                QStyle.State(QStyle.State_Selected):
            pen.setWidth(2)
        else:
            pen.setWidth(1)

        offsetX = self.rect().x()
        offsetY = self.rect().y()
        w = self.rect().width()
        latchW = w / 3.0
        latchH = min(15.0, latchW)
        h = self.rect().height() - latchH + 1

        painter.setPen(pen)
        painter.setBrush(self.brush())
        painter.setFont(self.font)

        painter.drawRect(offsetX, offsetY, latchW, latchH)
        painter.drawRect(offsetX, offsetY + latchH, w, h)
        y = self.margin + self.header.boundingRect().height() + latchH
        painter.drawLine(offsetX, offsetY + y, offsetX + w - 1, offsetY + y)

        self.adjustAssociations()
示例#2
0
 def paintHorizontalSection(self, painter: QPainter, sectionRect: QRect,
                            logicalLeafIndex: int, hv: QHeaderView,
                            styleOptions: QStyleOptionHeader,
                            leafIndex: QModelIndex):
     #            print(logicalLeafIndex)
     oldBO = painter.brushOrigin()
     top = sectionRect.y()
     indexes = QModelIndexList(self.parentIndexes(leafIndex))
     for i in range(indexes.size()):
         realStyleOptions = QStyleOptionHeader(styleOptions)
         if i < indexes.size() - 1 and (
                 realStyleOptions.state & QStyle.State_Sunken
                 or realStyleOptions.state & QStyle.State_On):
             t = QStyle.State(QStyle.State_Sunken | QStyle.State_On)
             realStyleOptions.state = realStyleOptions.state & ~t  # FIXME: parent items are not highlighted
         if i < indexes.size(
         ) - 1:  # Use sortIndicator for inner level only
             realStyleOptions.sortIndicator = False
         #                if i==0:
         #                    print(self.leafs(indexes[i]), leafIndex)
         top = self.paintHorizontalCell(painter, hv, indexes[i],
                                        leafIndex, logicalLeafIndex,
                                        realStyleOptions, sectionRect,
                                        top)
     painter.setBrushOrigin(oldBO)
示例#3
0
    def paint(self, painter, option, widget=None):
        """
        Public method to paint the item in local coordinates.
        
        @param painter reference to the painter object (QPainter)
        @param option style options (QStyleOptionGraphicsItem)
        @param widget optional reference to the widget painted on (QWidget)
        """
        if (option.state & QStyle.State_Selected) == \
                QStyle.State(QStyle.State_Selected):
            width = 2
        else:
            width = 1

        # draw the line first
        line = QLineF(self._origin, self._end)
        painter.setPen(
            QPen(Qt.black, width, Qt.SolidLine, Qt.FlatCap, Qt.MiterJoin))
        painter.drawLine(line)

        # draw the arrow head
        arrowAngle = self._type * ArrowheadAngleFactor
        slope = math.atan2(line.dy(), line.dx())

        # Calculate left arrow point
        arrowSlope = slope + arrowAngle
        a1 = QPointF(self._end.x() - self._halfLength * math.cos(arrowSlope),
                     self._end.y() - self._halfLength * math.sin(arrowSlope))

        # Calculate right arrow point
        arrowSlope = slope - arrowAngle
        a2 = QPointF(self._end.x() - self._halfLength * math.cos(arrowSlope),
                     self._end.y() - self._halfLength * math.sin(arrowSlope))

        if self._filled:
            painter.setBrush(Qt.black)
        else:
            painter.setBrush(Qt.white)
        polygon = QPolygonF()
        polygon.append(line.p2())
        polygon.append(a1)
        polygon.append(a2)
        painter.drawPolygon(polygon)
示例#4
0
    def paint(self, painter, option, widget=None):
        """
        Public method to paint the item in local coordinates.
        
        @param painter reference to the painter object (QPainter)
        @param option style options (QStyleOptionGraphicsItem)
        @param widget optional reference to the widget painted on (QWidget)
        """
        pen = self.pen()
        if (option.state & QStyle.State_Selected) == \
                QStyle.State(QStyle.State_Selected):
            pen.setWidth(2)
        else:
            pen.setWidth(1)

        painter.setPen(pen)
        painter.setBrush(self.brush())
        painter.drawRect(self.rect())
        self.adjustAssociations()
示例#5
0
 def paintVerticalSection(self, painter: QPainter, sectionRect: QRect,
                          logicalLeafIndex: int, hv: QHeaderView,
                          styleOptions: QStyleOptionHeader,
                          leafIndex: QModelIndex):
     oldBO = painter.brushOrigin()
     left = sectionRect.x()
     indexes = QModelIndexList(self.parentIndexes(leafIndex))
     for i in range(indexes.size()):
         realStyleOptions = QStyleOptionHeader(styleOptions)
         if i < indexes.size() - 1 and (
                 realStyleOptions.state & QStyle.State_Sunken
                 or realStyleOptions.state & QStyle.State_On):
             t = QStyle.State(QStyle.State_Sunken | QStyle.State_On)
             realStyleOptions.state = realStyleOptions.state & ~t  # FIXME: parent items are not highlighted
         left = self.paintVerticalCell(painter, hv, indexes[i],
                                       leafIndex, logicalLeafIndex,
                                       realStyleOptions, sectionRect,
                                       left)
     painter.setBrushOrigin(oldBO)