1
我想通过编写Go游戏实现来教自己python。 我想为石头制作一个自定义的QGrapicsItem。为什么我的Custom QGraphicsItem不显示在预期的坐标上?
目前它只应绘制一个以给定坐标(测试)为中心的圆。 但由于某种原因,该项目出现在我场景上的不同坐标上。 不同的我的意思是,我已经画出了现场的董事会的网格线,并用我用于网格的相同坐标来调用我的Stone项目,但它并没有出现在预期的网格点上。
我对StoneItem代码:
from PyQt5.QtWidgets import QGraphicsItem
from PyQt5.QtCore import QRectF
class Stone(QGraphicsItem):
"""
A Go stone QGraphicsItem
x, y :: center Coords of Stone
rad :: radius
color:: the stone type
0, self.empty :: empty
1, self.black :: black
2, self.white :: white
"""
empty = 0
black = 1
white = 2
def __init__(self, x, y, rad, color):
super().__init__()
self.x = x
self.y = y
self.rad = rad
self.color = color
self.setPos(x, y)
def boundingRect(self):
rect = QRectF(-self.rad, -self.rad,
self.rad, self.rad)
return rect
def paint(self, painter, *args, **kwargs):
painter.drawEllipse(self.boundingRect())
欲了解更多情况下整个代码可以在https://github.com/drseilzug/GoGote/blob/master/GoGote/BoardGUI.py
发现我还是相当新的PyQt5与解释解决方案,帮助我理解,我错了,将不胜感激。
谢谢 drseilzug