pyqt - Drag and drop a point on the canvas -


Can I use drag and drop technology at a point in a quadrant? I can not really find a slot on the canvas to connect with a mouse click.

  class canvas (QtGui.QWidget): def __init __ (self, parent): super (canvas, self). __init __ (parent) self.setGeometry (0,0,200,200) paintEvent (self, e) def: QP = QtGui.QPainter (qp.begin) self.drawPoints (QP) qp.end () DEF drawPoints (self, QP): Qp.setPen (QtCore.Qt.red) Size = self.size () #test x = 0 y = 0 for category (0,150,2): qp.drawpoint (x, y) x + = 5 Y + = 5 # Click the coordinate def mousePressEvent (Self, QMouseEvent): Print QMouseEvent.pos ()  

Drag a drop technique is more or less like this:

  1. On click: Identify the dragging object
  2. On the trick: Draw the drawing object again
  3. On release: Update last state

You can also update canvas on AP2. This is an example of the technique I use samples to manage points (hope you do not bother). QtGui imported from PyQt4 import, QtCore NP class canvas (QtGui.QWidget) imports the egg: DELTA = 10 # minimum distance def for __init __ (self, parent): super (canvas, self) .__ init __ (Parent) self.draggin_idx = -1 self.setGeometry (0,0,200,200) self.points = np.array (V [5, V * 5] in the category V (75)], dtype = np.float def PaintEvent (self, e): qp = QtGui.QPainter () qp.begin (self) self.drawPoints (qp) qp.end () Def Draw (self, qp): qp.setPen (QtCore.Qt.red) x , Self.points for y: qp.drawpoint (x, y) def _get_point (self, evt): return np.array ([evt .pos () .x (), evt.pos () .Y ()] ) #get def defender mousePressEvent (self, evt): if evt.button () == QtCore.Qt.LeftButton And self.draggin_idx == -1: point = self._get_point (evt) #dist wil I click from point to point = distance = sppoints = point dist = dist [], 0] ** 2 + dist [:, 1] * * 2 districts [districts> self DELTA] = Hold square distance from NP. At the distance of DLTA, IIT # OBVETE, if z. Me () & Lt; Np.inf: self.draggin_idx = dist.argmin () DEF mouseMoveEvent (self, evt): if self.draggin_idx = -1: point = self._get_point (evt) self.points [self.draggin_idx] = point itself. Update () DEF mouseReleaseEvent (self, evt): evt.button () == QtCore.Qt.LeftButton and self.draggin_idx if = -1: point = self._get_point (evt) self.points [self.draggin_idx] = dot Self.draggin_idx = -1 self.update () AP = QtGui.QApplication ([]) C = canvas (none) c.show () app.exec_ ()

< / Html>

Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -