3
3
4
4
本章教程,讲的是 PyQt6 中的拖拽操作。
5
5
6
- 计算机图形界面中,拖拽操作是点击一个对象不放,把它放在另外一个地方或者另外一个对象上面的操作。一半来说 ,这会触发很多类型的行为,或者在两个对象上建立多种关系。
6
+ 计算机图形界面中,拖拽操作是点击一个对象不放,把它放在另外一个地方或者另外一个对象上面的操作。一般来说 ,这会触发很多类型的行为,或者在两个对象上建立多种关系。
7
7
8
8
在计算机图形用户界面中,拖放是(或支持)点击虚拟对象并将其拖到不同位置或另一个虚拟对象上的动作。 一般来说,它可以用来调用多种动作,或者在两个抽象对象之间创建各种类型的关联。
9
9
@@ -166,7 +166,7 @@ class Button(QPushButton):
166
166
167
167
def mouseMoveEvent (self , e ):
168
168
169
- if e.buttons() != Qt.MouseButtons .RightButton:
169
+ if e.buttons() != Qt.MouseButton .RightButton:
170
170
return
171
171
172
172
mimeData = QMimeData()
@@ -183,7 +183,7 @@ class Button(QPushButton):
183
183
184
184
super ().mousePressEvent(e)
185
185
186
- if e.button() == Qt.MouseButtons .LeftButton:
186
+ if e.button() == Qt.MouseButton .LeftButton:
187
187
print (' press' )
188
188
189
189
@@ -243,7 +243,7 @@ class Button(QPushButton):
243
243
基于 ` QPushButton ` 创建了一个 ` Button ` 类,并实现了两个 ` QPushButton ` 方法:` mouseMoveEvent ` 和 ` mousePressEvent ` 。` mouseMoveEvent ` 方法是处理拖放操作开始的地方。
244
244
245
245
``` python
246
- if e.buttons() != Qt.MouseButtons .RightButton:
246
+ if e.buttons() != Qt.MouseButton .RightButton:
247
247
return
248
248
```
249
249
定义鼠标右键为触发拖拽操作的按钮,鼠标左键只会触发点击事件。
@@ -266,7 +266,7 @@ def mousePressEvent(self, e):
266
266
267
267
super ().mousePressEvent(e)
268
268
269
- if e.button() == Qt.MouseButtons .LeftButton:
269
+ if e.button() == Qt.MouseButton .LeftButton:
270
270
print (' press' )
271
271
```
272
272
如果鼠标左键点击按钮,会在控制台打印 'press' 消息,注意,这里在父级上也调用了 ` mousePressEvent ` 方法,不然按钮按下的动作不会展现出来。
0 commit comments