python-3.x - 有拖动数据时未触发 mouseReleaseEvent?
问题描述
在我的测试演示中,mouseReleaseEvent
当mouseMoveEvent
使用QDrag
. mouseReleaseEvent
当我拖动某些东西时,我也想工作。
class Item2(QGraphicsItem):
def boundingRect(self):
return QRectF(-50, -50, 100, 100)
def paint(self, p, o, w):
p.setBrush(Qt.red)
p.drawRect(-50, -50, 100, 100)
def mousePressEvent(self, e):
if e.button() == Qt.LeftButton:
self.setCursor(Qt.ClosedHandCursor)
print('press')
def mouseMoveEvent(self, e):
if QLineF(e.buttonDownScreenPos(Qt.LeftButton), e.screenPos()).length() > QApplication.startDragDistance():
drag = QDrag(e.widget())
data = QMimeData()
data.setText('Test')
drag.setMimeData(data)
drag.exec()
print('move')
def mouseReleaseEvent(self, e):
self.setCursor(Qt.ArrowCursor)
print('release')
class Demo2(QGraphicsView):
def __init__(self):
super().__init__()
self.scene = QGraphicsScene()
self.scene.addItem(Item2())
self.setScene(self.scene)
app = QApplication([])
demo = Demo2()
demo.resize(800, 800)
demo.show()
app.exec()
解决方案
推荐阅读
- linux - 构建 Docker 镜像时安装 Anaconda 和软件包
- javascript - Vue.js 无法检查用户是否已登录计算属性
- python - 最近的聚类距离(无质心)
- c# - Luis Dialog Sample 不等待用户输入
- java - java在else语句中的方法中返回一个字符串
- php - 警告:使用未定义的常量 UPLOAD_DIR 假定为 'UPLOAD_DIR' 警告:遇到非数字值
- python - 按一列分组,然后对其余各列进行平均。熊猫数据框
- typescript - Typescript:使通用类型化参数从函数流向函数
- machine-learning - 在多标签图像分类的背景下,将随机裁剪作为一种数据增强技术是否可行?
- python - 无法从 Ray Actor 进程初始化超类