我有一个问题,我有这些“饼切片”,每个都需要可选择但由于Qt的性质,似乎每个只能有一个边界矩形。我需要某种三角形。使用矩形意味着每个切片的矩形将与其他切片矩形重叠,或者每个矩形必须小尺寸以适合切片,这将在切片中留下许多其他空白空间。
有什么想法吗?
这是我创建的用于生成切片的类,如果有帮助的话:
class Link_Point(QGraphicsItem):
""" Connection points for object link """
RECT = Component_Point.RECT.adjusted(BORDER_WIDTH/2, BORDER_WIDTH/2, -BORDER_WIDTH/2, -BORDER_WIDTH/2)
def __init__(self, type, parent=None):
super(Link_Point, self).__init__(parent)
# Vars
self.type = type
self.start_angle= 0
self.span = 0
# Settings
self.setFlags( QGraphicsItem.ItemIsSelectable |
QGraphicsItem.ItemIsMovable | # ********* remove this line
QGraphicsItem.ItemIsFocusable )
def Set_Span(self, start_angle, span):
self.start_angle= start_angle
self.span = span
self.update()
def boundingRect(self):
# *** set bounding rect propperly
return Component_Point.RECT
def paint(self, painter, option, widget):
# Draw Pie Slice
pen = QPen()
pen.setStyle(Qt.NoPen)
painter.setPen(pen)
brush = QBrush(LINKCOLOR_DIC[self.type])
painter.setBrush(brush)
painter.drawPie(Link_Point.RECT, self.start_angle, self.span)