Update 拖拽.md

This commit is contained in:
maicss 2016-10-08 18:17:53 -05:00
parent 2b12eea766
commit 7a1ef1499c

View File

@ -243,14 +243,14 @@ def mousePressEvent(self, e):
if e.button() == Qt.LeftButton:
print('press')
```
We print 'press' to the console if we left click on the button with the mouse. Notice that we call mousePressEvent() method on the parent as well. Otherwise, we would not see the button being pushed.
左键点击按钮会在控制台输出“press”。注意我们在父级上也调用了`mousePressEvent()`方法,不然的话,我们是看不到按钮按下的效果的。
```
position = e.pos()
self.button.move(position)
```
In the dropEvent() method we code what happens after we release the mouse button and finish the drop operation. We find out the current mouse pointer position and move the button accordingly.
`dropEvent()`方法里,我们定义了按钮按下后和释放后的行为,获得鼠标移动的位置,然后把按钮放到这个地方。
```
e.setDropAction(Qt.MoveAction)
e.accept()
```
We specify the type of the drop action. In our case it is a move action.
指定放下的动作类型为moveAction。