def setupScene(self): self.m_scene.setSceneRect(-300, -200, 600, 460) linearGrad = QtGui.QLinearGradient(QtCore.QPointF(-100, -100), QtCore.QPointF(100, 100)) linearGrad.setColorAt(0, QtGui.QColor(255, 255, 255)) linearGrad.setColorAt(1, QtGui.QColor(192, 192, 255)) self.setBackgroundBrush(linearGrad) radialGrad = QtGui.QRadialGradient(30, 30, 30) radialGrad.setColorAt(0, QtCore.Qt.yellow) radialGrad.setColorAt(0.2, QtCore.Qt.yellow) radialGrad.setColorAt(1, QtCore.Qt.transparent) pixmap = QtGui.QPixmap(60, 60) pixmap.fill(QtCore.Qt.transparent) painter = QtGui.QPainter(pixmap) painter.setPen(QtCore.Qt.NoPen) painter.setBrush(radialGrad) painter.drawEllipse(0, 0, 60, 60) painter.end() self.m_lightSource = self.m_scene.addPixmap(pixmap) self.m_lightSource.setZValue(2) for i in range(-2, 3): for j in range(-2, 3): if (i + j) & 1: item = QtGui.QGraphicsEllipseItem(0, 0, 50, 50) else: item = QtGui.QGraphicsRectItem(0, 0, 50, 50) item.setPen(QtGui.QPen(QtCore.Qt.black, 1)) item.setBrush(QtGui.QBrush(QtCore.Qt.white)) effect = QtGui.QGraphicsDropShadowEffect(self) effect.setBlurRadius(8) item.setGraphicsEffect(effect) item.setZValue(1) item.setPos(i * 80, j * 80) self.m_scene.addItem(item) self.m_items.append(item)
def addItem(self, item, row=None, col=None, rowspan=1, colspan=1): """ Add an item to the layout and place it in the next available cell (or in the cell specified). The item must be an instance of a QGraphicsWidget subclass. """ if row is None: row = self.currentRow if col is None: col = self.currentCol self.items[item] = [] for i in range(rowspan): for j in range(colspan): row2 = row + i col2 = col + j if row2 not in self.rows: self.rows[row2] = {} self.rows[row2][col2] = item self.items[item].append((row2, col2)) borderRect = QtGui.QGraphicsRectItem() borderRect.setParentItem(self) borderRect.setZValue(1e3) borderRect.setPen(fn.mkPen(self.border)) self.itemBorders[item] = borderRect #this does not work in the original src code. i dont care, just ignore the exception... try: item.geometryChanged.connect(self._updateItemBorder) except: bla = 1 self.layout.addItem(item, row, col, rowspan, colspan) self.layout.activate() # Update layout, recalculating bounds. # Allows some PyQtGraph features to also work without Qt event loop. self.nextColumn()
kineticPix = QtGui.QPixmap(':/images/kinetic.png') bgPix = QtGui.QPixmap(':/images/Time-For-Lunch-2.jpg') scene = QtGui.QGraphicsScene(-350, -350, 700, 700) items = [] for i in range(64): item = Pixmap(kineticPix) item.pixmap_item.setOffset(-kineticPix.width() / 2, -kineticPix.height() / 2) item.pixmap_item.setZValue(i) items.append(item) scene.addItem(item.pixmap_item) # Buttons. buttonParent = QtGui.QGraphicsRectItem() ellipseButton = Button(QtGui.QPixmap(':/images/ellipse.png'), buttonParent) figure8Button = Button(QtGui.QPixmap(':/images/figure8.png'), buttonParent) randomButton = Button(QtGui.QPixmap(':/images/random.png'), buttonParent) tiledButton = Button(QtGui.QPixmap(':/images/tile.png'), buttonParent) centeredButton = Button(QtGui.QPixmap(':/images/centered.png'), buttonParent) ellipseButton.setPos(-100, -100) figure8Button.setPos(100, -100) randomButton.setPos(0, 0) tiledButton.setPos(-100, 100) centeredButton.setPos(100, 100) scene.addItem(buttonParent) buttonParent.scale(0.75, 0.75) buttonParent.setPos(200, 200)
def _build(self, margin=5): """ Create a node reprensenting a box. Parameters ---------- margin: int (optional, default 5) the default margin. """ # Create a title for the node self.title = QtGui.QGraphicsTextItem(self.get_title(), self) font = self.title.font() font.setWeight(QtGui.QFont.Bold) self.title.setFont(font) self.title.setPos(margin, margin) self.title.setZValue(2) self.title.setParentItem(self) # Define the default control position control_position = ( margin + margin + self.title.boundingRect().size().height()) # Create the input controls for input_name in self.inputs: # Create the control representation control_glyph, control_text = self._create_control( input_name, control_position, is_output=False, margin=margin) # Update the class parameters self.input_controls[input_name] = (control_glyph, control_text) # Update the next control position control_position += control_text.boundingRect().size().height() # Create the output controls for output_name in self.outputs: # Create the control representation control_glyph, control_text = self._create_control( output_name, control_position, is_output=True, margin=margin) # Update the class parameters self.output_controls[output_name] = (control_glyph, control_text) # Update the next control position control_position += control_text.boundingRect().size().height() # Define the box node self.box = QtGui.QGraphicsRectItem(self) self.box.setBrush(self.background_brush) self.box.setPen(QtGui.QPen(QtCore.Qt.NoPen)) self.box.setZValue(-1) self.box.setParentItem(self) self.box.setRect(self.contentsRect()) self.box_title = QtGui.QGraphicsRectItem(self) rect = self.title.mapRectToParent(self.title.boundingRect()) brect = self.contentsRect() brect.setWidth(brect.right() - margin) rect.setWidth(brect.width()) self.box_title.setRect(rect) self.box_title.setBrush(self.title_brush) self.box_title.setPen(QtGui.QPen(QtCore.Qt.NoPen)) self.box_title.setParentItem(self)