Fixup layout?
parent
76dd861bc1
commit
dea4168dce
|
@ -1,4 +1,4 @@
|
||||||
venv/
|
venv/
|
||||||
demos/
|
demos/
|
||||||
.idea/
|
.idea/
|
||||||
*.__pycache__/
|
*/__pycache__/*
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
from PyQt5.QtGui import QPainter, QBrush, QPen, QColor, QFont
|
from PyQt5.QtGui import QPainter, QBrush, QPen, QColor, QFont
|
||||||
from PyQt5.QtWidgets import (QGraphicsScene, QGraphicsWidget, QGraphicsItem,
|
from PyQt5.QtWidgets import (QSizePolicy, QGraphicsWidget, QGraphicsItem,
|
||||||
QGraphicsLineItem, QGraphicsRectItem, QGraphicsObject,
|
QGraphicsLineItem, QGraphicsRectItem, QGraphicsObject,
|
||||||
QGraphicsItemGroup, QGraphicsPathItem, QGraphicsLinearLayout)
|
QGraphicsItemGroup, QGraphicsPathItem, QGraphicsLinearLayout)
|
||||||
from PyQt5.QtCore import (QAbstractAnimation, QObject, QPointF, Qt, QRectF, QLineF,
|
from PyQt5.QtCore import (QAbstractAnimation, QObject, QPointF, Qt, QRectF, QLineF,
|
||||||
|
@ -16,6 +16,12 @@ class BoxBoard(QGraphicsWidget):
|
||||||
self.width = width
|
self.width = width
|
||||||
self.height = height
|
self.height = height
|
||||||
self.circumference = 2*(width+height)
|
self.circumference = 2*(width+height)
|
||||||
|
self.setMinimumSize(QSizeF(width, height))
|
||||||
|
self.setMaximumSize(QSizeF(width, height))
|
||||||
|
|
||||||
|
self.size_policy = QSizePolicy(QSizePolicy.Minimum, QSizePolicy.Minimum)
|
||||||
|
self.size_policy.setHeightForWidth(True)
|
||||||
|
self.setSizePolicy(self.size_policy)
|
||||||
|
|
||||||
# Set up pens for drawing
|
# Set up pens for drawing
|
||||||
self.default_pen = QPen()
|
self.default_pen = QPen()
|
||||||
|
@ -31,8 +37,8 @@ class BoxBoard(QGraphicsWidget):
|
||||||
self.line_order = [self.up, self.right, self.down, self.left]
|
self.line_order = [self.up, self.right, self.down, self.left]
|
||||||
|
|
||||||
# Reimplemented boundingRect
|
# Reimplemented boundingRect
|
||||||
def boundingRect(self):
|
#def boundingRect(self):
|
||||||
return QRectF(-5, -5, self.width+10, self.height+10)
|
# return QRectF(-5, -5, self.width+10, self.height+10)
|
||||||
|
|
||||||
# Reimplemented paint
|
# Reimplemented paint
|
||||||
def paint(self, painter, style, widget=None):
|
def paint(self, painter, style, widget=None):
|
||||||
|
@ -41,9 +47,11 @@ class BoxBoard(QGraphicsWidget):
|
||||||
if line.length() > 1:
|
if line.length() > 1:
|
||||||
painter.drawLine(line)
|
painter.drawLine(line)
|
||||||
#painter.drawRect(self.geometry())
|
#painter.drawRect(self.geometry())
|
||||||
|
super().paint(painter, style, widget)
|
||||||
|
|
||||||
def sizeHint(self, which, constraint=None):
|
#def sizeHint(self, which, constraint=None):
|
||||||
return QSizeF(self.width, self.height)
|
# super().sizeHint(which, constraint)
|
||||||
|
# return QSizeF(self.width, self.height)
|
||||||
|
|
||||||
|
|
||||||
class GameBoard(BoxBoard):
|
class GameBoard(BoxBoard):
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
from PyQt5.QtGui import QPainter, QBrush, QPen, QColor, QFont
|
from PyQt5.QtGui import QPainter, QBrush, QPen, QColor, QFont
|
||||||
from PyQt5.QtWidgets import (QGraphicsScene, QGraphicsWidget, QGraphicsItem,
|
from PyQt5.QtWidgets import (QSizePolicy, QGraphicsWidget, QGraphicsItem,
|
||||||
QGraphicsLineItem, QGraphicsRectItem, QGraphicsObject,
|
QGraphicsLineItem, QGraphicsRectItem, QGraphicsObject,
|
||||||
QGraphicsItemGroup, QGraphicsLayoutItem)
|
QGraphicsItemGroup, QGraphicsLayoutItem)
|
||||||
from PyQt5.QtCore import (QAbstractAnimation, QObject, QPointF, Qt, QRectF, QLineF,
|
from PyQt5.QtCore import (QAbstractAnimation, QObject, QPointF, Qt, QRectF, QLineF,
|
||||||
|
@ -21,25 +21,17 @@ class TimerDisplayer(QGraphicsWidget):
|
||||||
|
|
||||||
|
|
||||||
self.timer_box = QRectF(0, 0, self.width, self.height)
|
self.timer_box = QRectF(0, 0, self.width, self.height)
|
||||||
#self.setGeometry(self.timer_box)
|
self.setMinimumSize(QSizeF(self.width, self.height))
|
||||||
#print(self.geometry().width())
|
self.setMaximumSize(QSizeF(self.width, self.height))
|
||||||
|
|
||||||
|
self.size_policy = QSizePolicy(QSizePolicy.Minimum, QSizePolicy.Minimum)
|
||||||
|
self.size_policy.setHeightForWidth(True)
|
||||||
|
self.setSizePolicy(self.size_policy)
|
||||||
|
|
||||||
def paint(self, painter, style, widget=None):
|
def paint(self, painter, style, widget=None):
|
||||||
box = self.geometry()
|
box = self.timer_box
|
||||||
#print(self.size().width())
|
#print(self.size().width())
|
||||||
painter.setPen(self.box_pen)
|
painter.setPen(self.box_pen)
|
||||||
painter.drawRect(box)
|
painter.drawRect(box)
|
||||||
painter.drawText(box, Qt.AlignCenter, "00:00")
|
painter.drawText(box, Qt.AlignCenter, "00:00")
|
||||||
|
|
||||||
def boundingRect(self):
|
|
||||||
return QRectF(QPointF(0, 0), self.geometry().size())
|
|
||||||
|
|
||||||
def sizeHint(self, which, constraint=None):
|
|
||||||
return QSizeF(self.width, self.height)
|
|
||||||
#print(self.geometry().size().width(), self.geometry().size().height())
|
|
||||||
#return self.geometry().size()
|
|
||||||
|
|
||||||
def setGeometry(self, rect):
|
|
||||||
self.prepareGeometryChange()
|
|
||||||
QGraphicsLayoutItem.setGeometry(self, rect)
|
|
||||||
self.setPos(rect.topLeft())
|
|
||||||
|
|
29
main.py
29
main.py
|
@ -16,43 +16,38 @@ class SudokuWindow(QGraphicsView):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
# Set up the Scene to manage the GraphicItems
|
# Set up the Scene to manage the GraphicItems
|
||||||
self.scene = QGraphicsScene(0, 0, 400, 500, self)
|
self.scene = QGraphicsScene(0, 0, 420, 500, self)
|
||||||
|
|
||||||
self.setScene(self.scene)
|
self.setScene(self.scene)
|
||||||
self.setSceneRect(self.scene.sceneRect())
|
self.setSceneRect(self.scene.sceneRect())
|
||||||
self.gameboard = board.GameBoard(400, 400)
|
self.gameboard = board.GameBoard(400, 400)
|
||||||
self.menuboard = board.MenuBoard(400, 80)
|
self.menuboard = board.MenuBoard(400, 80)
|
||||||
|
|
||||||
|
#self.gameboard = board.BoxBoard(400, 400)
|
||||||
|
#self.menuboard = board.BoxBoard(400, 50)
|
||||||
|
|
||||||
|
self.form = QGraphicsWidget()
|
||||||
self.layout = QGraphicsLinearLayout(Qt.Vertical)
|
self.layout = QGraphicsLinearLayout(Qt.Vertical)
|
||||||
self.layout.addItem(self.gameboard)
|
self.layout.addItem(self.gameboard)
|
||||||
self.layout.addItem(self.menuboard)
|
self.layout.addItem(self.menuboard)
|
||||||
self.form = QGraphicsWidget()
|
self.layout.setSpacing(10)
|
||||||
|
self.layout.setContentsMargins(10, 10, 10, 0)
|
||||||
self.form.setLayout(self.layout)
|
self.form.setLayout(self.layout)
|
||||||
|
|
||||||
self.scene.addItem(self.form)
|
self.scene.addItem(self.form)
|
||||||
self.setBackgroundBrush(QBrush(Qt.black))
|
self.setBackgroundBrush(QBrush(Qt.black))
|
||||||
self.setRenderHint(QPainter.Antialiasing)
|
self.setRenderHint(QPainter.Antialiasing)
|
||||||
self.setGeometry(0, 0, 600, 600)
|
#self.setGeometry(self.scene.sceneRect().toRect())
|
||||||
|
|
||||||
self.ensureVisible(self.scene.sceneRect(), 10, 10)
|
#self.ensureVisible(self.scene.sceneRect(), 50, 50)
|
||||||
self.fitInView(self.gameboard.boundingRect(), Qt.KeepAspectRatio)
|
self.fitInView(self.form.boundingRect(), Qt.KeepAspectRatio)
|
||||||
self.show()
|
self.show()
|
||||||
|
print(self.menuboard.geometry().height())
|
||||||
|
print(self.gameboard.boundingRect().height())
|
||||||
print('menuboard')
|
|
||||||
menubox = self.menuboard.geometry()
|
|
||||||
print(menubox.left(), menubox.top())
|
|
||||||
print(menubox.width(), menubox.height())
|
|
||||||
|
|
||||||
print('menuboard')
|
|
||||||
gamebox = self.gameboard.geometry()
|
|
||||||
print(gamebox.left(), gamebox.top())
|
|
||||||
print(gamebox.width(), gamebox.height())
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app = 0
|
app = 0
|
||||||
app = QApplication(sys.argv)
|
app = QApplication(sys.argv)
|
||||||
|
|
||||||
ex = SudokuWindow()
|
ex = SudokuWindow()
|
||||||
|
|
||||||
sys.exit(app.exec_())
|
sys.exit(app.exec_())
|
Loading…
Reference in New Issue