我有一个问题,我有这些“饼片”,每个都需要可选,但由于 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)