如何对我在 PyQt 中绘制的图形进行动画处理?
因此,我设法在屏幕上绘制了一个图形,如下所示:
class Window(QWidget):
#stuff
graphicsView = QGraphicsView(self)
scene = QGraphicsScene(self)
#draw our nodes and edges.
for i in range(0, len(MAIN_WORLD.currentMax.tour) - 1):
node = QGraphicsRectItem(MAIN_WORLD.currentMax.tour[i][0]/3, MAIN_WORLD.currentMax.tour[i][1]/3, 5, 5)
edge = QGraphicsLineItem(MAIN_WORLD.currentMax.tour[i][0]/3, MAIN_WORLD.currentMax.tour[i][1]/3,
MAIN_WORLD.currentMax.tour[i+1][0]/3, MAIN_WORLD.currentMax.tour[i+1][1]/3)
scene.addItem(node)
scene.addItem(edge)
#now go back and draw our connecting edge. Connects end to home node.
connectingEdge = QGraphicsLineItem(MAIN_WORLD.currentMax.tour[0][0]/3, MAIN_WORLD.currentMax.tour[0][1]/3,
MAIN_WORLD.currentMax.tour[len(MAIN_WORLD.currentMax.tour) - 1][0]/3, MAIN_WORLD.currentMax.tour[len(MAIN_WORLD.currentMax.tour) - 1][1]/3)
scene.addItem(connectingEdge)
graphicsView.setScene(scene)
hbox = QVBoxLayout(self)
#some more stuff..
hbox.addWidget(graphicsView)
self.setLayout(hbox)
现在,边缘将不断更新,因此我希望能够删除这些边缘并重新绘制它们。我怎样才能做到这一点?
So I've managed to get a graph drawn up on my screen like such:
class Window(QWidget):
#stuff
graphicsView = QGraphicsView(self)
scene = QGraphicsScene(self)
#draw our nodes and edges.
for i in range(0, len(MAIN_WORLD.currentMax.tour) - 1):
node = QGraphicsRectItem(MAIN_WORLD.currentMax.tour[i][0]/3, MAIN_WORLD.currentMax.tour[i][1]/3, 5, 5)
edge = QGraphicsLineItem(MAIN_WORLD.currentMax.tour[i][0]/3, MAIN_WORLD.currentMax.tour[i][1]/3,
MAIN_WORLD.currentMax.tour[i+1][0]/3, MAIN_WORLD.currentMax.tour[i+1][1]/3)
scene.addItem(node)
scene.addItem(edge)
#now go back and draw our connecting edge. Connects end to home node.
connectingEdge = QGraphicsLineItem(MAIN_WORLD.currentMax.tour[0][0]/3, MAIN_WORLD.currentMax.tour[0][1]/3,
MAIN_WORLD.currentMax.tour[len(MAIN_WORLD.currentMax.tour) - 1][0]/3, MAIN_WORLD.currentMax.tour[len(MAIN_WORLD.currentMax.tour) - 1][1]/3)
scene.addItem(connectingEdge)
graphicsView.setScene(scene)
hbox = QVBoxLayout(self)
#some more stuff..
hbox.addWidget(graphicsView)
self.setLayout(hbox)
Now, the edges are going to be updating constantly, so I want to be able to remove those edges and redraw them. How can I do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
QGraphicsScene
管理您添加到其中的项目的绘制。如果矩形或线条的位置发生了变化,您可以更新它们(如果您以前使用过它们):稍后,您可以更新节点的位置:
对于线条也是如此。
如果您需要删除一个,您可以使用
QGraphicsScene
manages the drawing of the items you've added to it. If the position of the rectangles or lines has changed you can update them if you old onto them:Later, you can update a node's position:
Similarly for lines.
If you need to remove one, you can use