Esempio n. 1
0
    def draw_event(self):
        rnd = random.Random()
        if not self.isDrawn:

            item = QtWidgets.QGraphicsEllipseItem(*self.get_params())
            self.graphicsScene.addItem(item)

            item = QtWidgets.QGraphicsEllipseItem(*self.get_params())
            self.graphicsScene.addItem(item)

            item = QtWidgets.QGraphicsEllipseItem(*self.get_params())
            item.setStartAngle(90)
            item.setSpanAngle(random.randrange(10, 100))
            self.graphicsScene.addItem(item)

            item = QtWidgets.QGraphicsEllipseItem(*self.get_params())
            item.setStartAngle(90 * 20)
            item.setSpanAngle(random.randrange(10, 100) * 20)
            self.graphicsScene.addItem(item)

            item = QtWidgets.QGraphicsRectItem(*self.get_params())
            self.graphicsScene.addItem(item)

            item = QtWidgets.QGraphicsRectItem(*self.get_params())
            self.graphicsScene.addItem(item)

            item = QtWidgets.QGraphicsLineItem()
            item.setLine(
                random.randrange(
                    0,
                    self.graphicsView.frameGeometry().width() - MAX_WIDTH),
                random.randrange(
                    0,
                    self.graphicsView.frameGeometry().height() - MAX_HEIGHT),
                random.randrange(
                    0,
                    self.graphicsView.frameGeometry().width() - MAX_WIDTH),
                random.randrange(
                    0,
                    self.graphicsView.frameGeometry().height() - MAX_HEIGHT))
            self.graphicsScene.addItem(item)

            item = QtWidgets.QGraphicsLineItem()
            item.setLine(
                random.randrange(
                    0,
                    self.graphicsView.frameGeometry().width() - MAX_WIDTH),
                random.randrange(
                    0,
                    self.graphicsView.frameGeometry().height() - MAX_HEIGHT),
                random.randrange(
                    0,
                    self.graphicsView.frameGeometry().width() - MAX_WIDTH),
                random.randrange(
                    0,
                    self.graphicsView.frameGeometry().height() - MAX_HEIGHT))
            self.graphicsScene.addItem(item)
            self.isDrawn = True
Esempio n. 2
0
File: app.py Progetto: Lukisn/MEPy
    def add_node(self):
        x = random.randint(-200, 200)
        y = random.randint(-150, 150)
        node = QtWidgets.QGraphicsEllipseItem(x, y, 10, 10)
        node.setPen(self.node_pen)
        node.setBrush(self.node_brush)
        node.setFlag(QtWidgets.QGraphicsItem.ItemIsSelectable)
        node.setFlag(QtWidgets.QGraphicsItem.ItemIsMovable)
        node.setCursor(Qt.PointingHandCursor)
        self.scene.addItem(node)

        self.maybe_save = True
        self.status_bar.showMessage(f"Added node at ({x}, {y})")
Esempio n. 3
0
 def create_possible_move_dots(self, from_coord):
     possible_coords = [
         move[3:] for move in
         [move for move in self.allowed_moves if move[:2] == from_coord]
     ]
     self.possible_move_dots = []
     for coord in possible_coords:
         position = self.square_at_coord[coord].boundingRect().center(
         ) - QtCore.QPointF(self.dot_size / 2, self.dot_size / 2)
         dot = QtWidgets.QGraphicsEllipseItem(position.x(), position.y(),
                                              self.dot_size, self.dot_size)
         dot.setBrush(QtGui.QBrush(QtCore.Qt.green))
         dot.setZValue(self.possible_move_dot_Z_value)
         self.possible_move_dots.append(dot)
         self.scene().addItem(dot)
Esempio n. 4
0
    def __init__(self, view):
        super(PainterTool, self).__init__(view)

        self._prec_pos = None
        self._prec_size = None

        self.is_editing_size = False
        self._size = None
        self.size = 5

        # preview item used when modifying size
        self.size_display_item = QtWidgets.QGraphicsEllipseItem()
        self.size_display_item.setPen(QtGui.QColor("red"))
        self.size_display_item.setZValue(99999)
        self.view.scene.addItem(self.size_display_item)

        self.update_cursor()
Esempio n. 5
0
    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 = QtWidgets.QGraphicsEllipseItem(0, 0, 50, 50)
                else:
                    item = QtWidgets.QGraphicsRectItem(0, 0, 50, 50)

                item.setPen(QtGui.QPen(QtCore.Qt.black, 1))
                item.setBrush(QtGui.QBrush(QtCore.Qt.white))

                effect = QtWidgets.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)
Esempio n. 6
0
        painter.drawPath(myPath)
        

def timerHandler(): 
    increment = 15
    blade1.setAngle(blade1.angle+increment)
    blade2.setAngle(blade2.angle+increment)
    blade3.setAngle(blade3.angle+increment)    
    view.viewport().repaint()

if __name__ == '__main__':
	app = QtWidgets.QApplication(sys.argv)
	scene = QtWidgets.QGraphicsScene(QtCore.QRectF(-100, -100, 200, 200))
	scene.addItem(QtWidgets.QGraphicsRectItem(scene.sceneRect()))	

	centerItem = QtWidgets.QGraphicsEllipseItem(QtCore.QRectF(-10, -10, 20, 20))	
	centerItem.setPen(QtGui.QPen(QtCore.Qt.darkBlue))
	centerItem.setBrush(QtCore.Qt.green)
	centerItem.setZValue(2)
	scene.addItem(centerItem)

	circle1 = QtWidgets.QGraphicsEllipseItem(QtCore.QRectF(-75, -75, 150, 150))
	circle1.setPen(QtGui.QPen(QtCore.Qt.black))
	circle1.setBrush(QtCore.Qt.NoBrush)
	# scene.addItem(circle1)

	blade1 = FanBlade()	
	scene.addItem(blade1)

	blade2 = FanBlade(120)
	scene.addItem(blade2)
Esempio n. 7
0
def main():		
	app = QtWidgets.QApplication(sys.argv)
	margin = 10
	scene = QtWidgets.QGraphicsScene(QtCore.QRectF(-200-margin/2, -200-margin/2, 400+margin, 400+margin))
	
	rect = QtWidgets.QGraphicsRectItem(scene.sceneRect().adjusted(1, 1, -1, -1))
	rect.setPen(QtGui.QPen(QtCore.Qt.red, 1))
	# scene.addItem(rect)
	
	radius = 200
	diameter = radius * 2	
	ellipseItem = QtWidgets.QGraphicsEllipseItem(QtCore.QRectF(-200, -200, diameter, diameter))
	ellipseItem.setPen(QtGui.QPen(QtCore.Qt.darkBlue))
	# ellipseItem.setBrush(QtCore.Qt.blue)
	scene.addItem(ellipseItem)	
	
	origin = QtCore.QPointF(0, 0)
	p1 = None
	p2 = None
	angle = 270
	line1 = None
	line2 = None
	conePath = QtGui.QPainterPath()

	def drawLine():
		nonlocal  p1
		nonlocal angle
		nonlocal line1
		nonlocal line2
		nonlocal origin		

		if p1 == None:
			angle2 = angle + 20

			p1 = QtCore.QPointF(radius * math.cos(angle * math.pi / 180.0),
				radius * math.sin(angle * math.pi / 180.0))
			p2 =  QtCore.QPointF(radius * math.cos(angle2 * math.pi / 180.0),
				radius * math.sin(angle2 * math.pi / 180.0))

			line1 = QtWidgets.QGraphicsLineItem(p1.x(), p1.y(), 0, 0)
			line2 = QtWidgets.QGraphicsLineItem(0, 0, p2.x(), p2.y())
			
			# conePath.moveTo(line1)
			# conePath.lineTo(line2)
			# conePath.closeSubpath()
			# scene.addPath(conePath)
			
			scene.addItem(line1)
			scene.addItem(line2)
		else:
			scene.removeItem(line1)
			scene.removeItem(line2)
			# scene.removeItem(conePath)

			angle += 1
			angle2 = angle + 20

			p1 = QtCore.QPointF(radius * math.cos(angle * math.pi / 180.0),
				radius * math.sin(angle * math.pi / 180.0))
			p2 =  QtCore.QPointF(radius * math.cos(angle2 * math.pi / 180.0),
				radius * math.sin(angle2 * math.pi / 180.0))

			line1 = QtWidgets.QGraphicsLineItem(p1.x(), p1.y(), 0, 0)
			line2 = QtWidgets.QGraphicsLineItem(0, 0, p2.x(), p2.y())

			# conePath.moveTo(line1)
			# conePath.lineTo(line2)
			# conePath.closeSubpath()
			# scene.addPath(conePath)

			scene.addItem(line1)
			scene.addItem(line2)		

	view = QtWidgets.QGraphicsView()
	view.setRenderHint(QtGui.QPainter.Antialiasing)
	view.setScene(scene)
	view.show()

	# drawLine()

	timer = QtCore.QTimer()
	timer.setInterval(100)
	timer.timeout.connect(drawLine)
	timer.start()

	sys.exit(app.exec_())