initial commit, nothing much here

This commit is contained in:
2024-03-06 11:34:29 +01:00
commit 787d4e776a
12 changed files with 269 additions and 0 deletions

64
grid/ui/window.py Normal file
View File

@@ -0,0 +1,64 @@
import sys
from PySide6.QtCore import Qt
from PySide6.QtGui import QBrush, QPainter, QPen
from PySide6.QtWidgets import (
QApplication,
QGraphicsEllipseItem,
QGraphicsRectItem,
QGraphicsScene,
QGraphicsView,
QHBoxLayout,
QVBoxLayout,
QWidget,
)
class Window(QWidget):
def __init__(self):
super().__init__()
# Defining a scene rect of 400x200, with it's origin at 0,0.
# If we don't set this on creation, we can set it later with .setSceneRect
self.scene = QGraphicsScene(0, 0, 600, 400)
for i in range(5):
# Draw a rectangle item, setting the dimensions.
rect = QGraphicsRectItem(0, 0, 200, 50)
rect.setPos(50+i*10, 20+ i*20)
brush = QBrush(Qt.GlobalColor.red)
rect.setBrush(brush)
# Define the pen (line)
pen = QPen(Qt.GlobalColor.cyan)
pen.setWidth(10)
rect.setPen(pen)
self.scene.addItem(rect)
ellipse = QGraphicsEllipseItem(0, 0, 100, 100)
ellipse.setPos(75, 30)
brush = QBrush(Qt.GlobalColor.blue)
ellipse.setBrush(brush)
pen = QPen(Qt.GlobalColor.green)
pen.setWidth(5)
ellipse.setPen(pen)
# Add the items to the scene. Items are stacked in the order they are added.
self.scene.addItem(ellipse)
# Define our layout.
hbox = QHBoxLayout()
view = QGraphicsView(self.scene)
view.setRenderHint(QPainter.RenderHint.Antialiasing)
vbox = QHBoxLayout(self)
vbox.addLayout(hbox)
vbox.addWidget(view)
self.setLayout(vbox)
app = QApplication(sys.argv)
w = Window()
w.show()
app.exec()