2014-02-20 4 views
0

여러 객체가있는 QCanvas가 있습니다. 캔버스를 업데이트하고 기존 객체를 삭제하지 않고 새 객체를 어떻게 배치 할 수 있습니까?기존 객체를 삭제하지 않고 캔버스 업데이트

새 캔버스를 그릴지라도 캔버스에 모든 기존 개체를 그려야합니다. 마우스 이벤트마다 새로운 객체가 생성됩니다.

class CANVAS(QtGui.QWidget): 
    def __init__(self , parent): 
     super(CANVAS , self).__init__(parent) 
     self.setGeometry(0 , 30 , 530 , 530) 
     self.frame = QtGui.QFrame(self) 
     self.CLICKED = 1 
     self.FUNCTION = 0 
     self.x ="" 
     self.y ="" 

    def paintEvent(self, e): 
     qp = QtGui.QPainter() 
     qp.begin(self) 
     self.drawPoints(qp) 
     qp.end() 


    def drawPoints(self, qp): 
     qp.setPen(QtCore.Qt.red) 

     t = points.point() 

     print self.x 
     if self.CLICKED == 1: 
      qp.drawRect(int(self.x), int(self.y), 10, 10) 
      self.CLICKED = 0 

     if self.FUNCTION == 1: 
      for k in range(0,360,1): 
       radius = 50 
       a = float(self.x) + radius * np.cos(k) 
       b = float(self.y) + radius * np.sin(k) 
       qp.drawPoint(a,b) 

      qp.drawPoint(int(self.x), int(self.y)) 
      print "circle done" 
      self.FUNCTION = 0 

     elif self.FUNCTION == 2: 
      start_P = points.point(int(self.x), int(self.y)) 

      a = 15 
      b = 20 
      upperL = points.point((int(self.x) + (10 * a)), int(self.y)) 
      P = [start_P, upperL] 
      dummy1 = LinInt(P, qp) 

      leftL = points.point((int(self.x)), ((int(self.y))+(10*b))) 
      P = [start_P, leftL] 
      dummy2 = LinInt(P, qp) 

      tmp = dummy1.pop() 
      rightL = points.point((tmp.getX()),((int(self.y))+(10*b))) 
      P = [tmp, rightL] 
      LinInt(P, qp) 

      P = [leftL, rightL] 
      LinInt(P, qp) 
      self.FUNCTION = 0 

      print "rectangle done" 
     elif self.FUNCTION == 3: 
      print "curve" 

    def mousePressEvent(self, event): 
     self.x = "" 
     self.y = "" 
     coordinates = event.x() 
     for i in str(coordinates): 
      if i.isdigit(): 
       self.x+=i 
     coordinates = event.y() 
     for i in str(coordinates): 
      if i.isdigit(): 
       self.y+=i 
     self.CLICKED = 1 
     self.update() 
+0

몇 가지 예제 코드를 게시 할 수 있습니까? 그것 없이는 나는 너를 도울 수 없다. –

+0

시도한 것을 보여주십시오. – Schollii

+0

죄송합니다. 방금 질문을 업데이트했습니다. – erbal

답변

0

생성자에서 빈 목록을 만듭니다. drawPoints에서 다음을 수행하십시오.

if self.CLICKED == 1: 
    rect = QRect(int(self.x), int(self.y), 10, 10) 
    self.rects.append(rect) 
    qp.drawRects(self.rects) 
관련 문제