【发布时间】:2019-11-18 13:50:15
【问题描述】:
背景:我正在尝试使用 Qt Graphics View 框架在 python 中制作 VR 演示,该框架允许自定义呈现的 GUI。我可以选择包装 Qt 的两个不同的 Python 模块:PyQt5 和 PySide2。不幸的是,这些模块中的每一个似乎都缺少图形视图框架中的不同关键要素。
PyQt5 似乎缺少QGraphicsSceneMouseEvent 的构造函数,这是从 VR 控制器手势创建合成鼠标事件所必需的。这个简短的 PyQt5 程序...
from PyQt5.QtCore import QEvent, QPointF, Qt
from PyQt5.QtGui import QMouseEvent
from PyQt5.QtWidgets import QGraphicsSceneMouseEvent
from PyQt5.QtGui import QOpenGLPaintDevice # No problem for PyQt5
pos = QPointF(20, 20)
event1 = QMouseEvent(QEvent.MouseMove, pos, Qt.LeftButton, Qt.LeftButton, Qt.NoModifier)
device = QOpenGLPaintDevice(100, 100)
# Problem: TypeError: PyQt5.QtWidgets.QGraphicsSceneMouseEvent cannot be instantiated or sub-classed
event2 = QGraphicsSceneMouseEvent(QEvent.GraphicsSceneMouseMove)
...结果为TypeError: PyQt5.QtWidgets.QGraphicsSceneMouseEvent cannot be instantiated or sub-classed
看似好消息是替代Qt绑定PySide2模块可以毫无怨言地构造QGraphicsSceneMouseEvent。但是PySide2 缺少 QOpenGLPaintDevice 类,我需要它来实际绘制小部件。这个非常相似的程序,它使用 PySide2...
from PySide2.QtCore import QEvent, QPointF, Qt
from PySide2.QtGui import QMouseEvent
from PySide2.QtWidgets import QGraphicsSceneMouseEvent
pos = QPointF(20, 20)
event1 = QMouseEvent(QEvent.MouseMove, pos, Qt.LeftButton, Qt.LeftButton, Qt.NoModifier)
event2 = QGraphicsSceneMouseEvent(QEvent.GraphicsSceneMouseMove) # No Problem for PySide2
from PySide2.QtGui import QOpenGLPaintDevice # Problem: PySide2 does not have this class
device = QOpenGLPaintDevice(100, 100)
结果为@987654331@
我不确定是否有人从 python 中成功使用过 Qt Graphics View 框架。如果没有,我想成为第一个。
【问题讨论】:
标签: python pyqt pyqt5 qgraphicsview pyside2