Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- """
- Created on Mon Apr 2 17:02:47 2018
- @author: Kergadon
- """
- #!/usr/bin/env python
- from PyQt5.QtCore import (QLineF, QPointF, QRectF, Qt)
- from PyQt5.QtCore import QRectF
- from PyQt5.QtGui import (QBrush, QColor, QPainter,QPen)
- from PyQt5.QtWidgets import (QApplication, QGraphicsView, QGraphicsScene, QGraphicsItem,
- QGridLayout, QVBoxLayout, QHBoxLayout,
- QLabel, QLineEdit, QPushButton,QGraphicsEllipseItem,QGraphicsLineItem)
- class node(QGraphicsEllipseItem):
- def __init__(self):
- super(node,self).__init__()
- self.num=0
- self.setBrush(QBrush(Qt.green,Qt.SolidPattern))
- def mousePressEvent(self, event):
- print('clicked')
- pos = event.pos()
- self.update()
- self.setBrush(QBrush(Qt.red,Qt.SolidPattern))
- super(node, self).mousePressEvent(event)
- class inverter(QGraphicsLineItem):
- def __init__(self):
- super(inverter,self).__init__()
- pen=QPen(Qt.red,Qt.SolidLine)
- pen.setWidth(6)
- self.setPen(pen)
- self.setLine(30, 50, 300, 300)
- def mousePressEvent(self, event):
- print('clicked')
- pos = event.pos()
- self.update()
- super(inverter, self).mousePressEvent(event)
- class MainWindow(QGraphicsView):
- def __init__(self):
- super(MainWindow, self).__init__()
- scene = QGraphicsScene(self)
- self.nodes=[node(),node(),node()]
- self.nodes[0].num=1
- self.nodes[1].num=2
- self.nodes[2].num=3
- for n in self.nodes:
- scene.addItem(n)
- self.nodes[0].setRect(20,40,20,20)
- self.nodes[1].setRect(20,80,20,20)
- self.nodes[2].setRect(20,120,20,20)
- self.line1=inverter()
- scene.addItem(self.line1)
- scene.setSceneRect(0, 0, 500, 500)
- self.setScene(scene)
- self.setCacheMode(QGraphicsView.CacheBackground)
- self.setWindowTitle("Node Diagram")
- def keyPressEvent(self, event):
- key = event.key()
- if key == Qt.Key_R:
- self.tic_tac_toe.reset()
- super(MainWindow, self).keyPressEvent(event)
- if __name__ == '__main__':
- import sys
- app = QApplication(sys.argv)
- mainWindow = MainWindow()
- mainWindow.show()
- sys.exit(app.exec_())
Advertisement
Add Comment
Please, Sign In to add comment