2013-03-01 100 views

回答

1

沒有辦法直接保存一個QGraphicsItem在一個文件中(除了一個像素圖),你可以重新加載。

但是,您可以創建一個文件,其中包含視圖中每個項目的說明。您需要做的是列出定義每個項目的每個信息(項目類型,位置,形狀等)並將它們存儲在一個文件中。

例如,收集了矩形,橢圓和線項目的信息:

scene = QGraphicsScene(); 
scene.addEllipse(100, 100, 50, 50) 
scene.addRect(200, 12, 120, 50) 
scene.addLine(50, 70, 100, 400) 

for item in scene.items(): 
    if item.type() == QGraphicsEllipseItem().type(): 
     print "Ellipse", item.rect() 
    elif item.type() == QGraphicsRectItem().type(): 
     print "Rectangle", item.rect() 
    elif item.type() == QGraphicsLineItem().type(): 
     print "Line", item.line().p1(), item.line().p2() 
+0

謝謝,然後我會用鹹菜。 – Alex 2013-03-01 16:47:09