Pythondef paint(self, painter, style_options, widget=0): if style_options.state & QStyle.State_Selected: # Рисуем при выделении как хотим, например, затемняем #...
Pythondef paint(self, painter, style_options, widget=0): if style_options.state & QStyle.State_Selected: # Настраиваем отображение элемента при его выделении мышкой pen = self.pen() brush = self.brush() color = pen.color() color.setAlphaF(self._selection_background_alpha) brush.setStyle(Qt.SolidPattern) brush.setColor(color) painter.setPen(pen) painter.setBrush(brush) painter.drawRect(self.boundingRect()) else: super(ImageRectItem, self).paint(painter, style_options, widget) pass
C++ (Qt)DiagramItem::DiagramItem(DiagramType diagramType, QMenu *contextMenu, QGraphicsItem *parent, QGraphicsScene *scene) : QGraphicsPolygonItem(parent, scene){ myDiagramType = diagramType; myContextMenu = contextMenu; QPainterPath path; switch (myDiagramType) { case StartEnd: path.moveTo(200, 50); path.arcTo(150, 0, 50, 50, 0, 90); path.arcTo(50, 0, 50, 50, 90, 90); path.arcTo(50, 50, 50, 50, 180, 90); path.arcTo(150, 50, 50, 50, 270, 90); path.lineTo(200, 25); myPolygon = path.toFillPolygon(); break; case Conditional: myPolygon << QPointF(-100, 0) << QPointF(0, 100) << QPointF(100, 0) << QPointF(0, -100) << QPointF(-100, 0); break; case Step: myPolygon << QPointF(-100, -100) << QPointF(100, -100) << QPointF(100, 100) << QPointF(-100, 100) << QPointF(-100, -100); break; default: myPolygon << QPointF(-120, -80) << QPointF(-70, 80) << QPointF(120, 80) << QPointF(70, -80) << QPointF(-120, -80); break; } setPolygon(myPolygon); setFlag(QGraphicsItem::ItemIsMovable, true); setFlag(QGraphicsItem::ItemIsSelectable, true); setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);}