!私はそれがどのように機能するかを完全には理解していません、
def mousePressEvent(self, event: QMouseEvent):
"""Dispatch Qt's mousePress event to corresponding function below"""
if event.button() == Qt.MiddleButton:
self.middleMouseButtonPress(event)
else:
super().mousePressEvent(event)
def mouseReleaseEvent(self, event: QMouseEvent):
"""Dispatch Qt's mouseRelease event to corresponding function below"""
if event.button() == Qt.MiddleButton:
self.middleMouseButtonRelease(event)
else:
super().mouseReleaseEvent(event)
def middleMouseButtonPress(self, event):
releaseEvent = QMouseEvent(QEvent.MouseButtonRelease, event.localPos(), event.screenPos(),
Qt.LeftButton, Qt.NoButton, event.modifiers())
super().mousePressEvent(releaseEvent)
self.setDragMode(QGraphicsView.ScrollHandDrag)
fakeEvent = QMouseEvent(event.type(), event.localPos(), event.screenPos(), Qt.LeftButton,
event.buttons() | Qt.LeftButton, event.modifiers())
super().mousePressEvent(fakeEvent)
def middleMouseButtonRelease(self, event):
print('MMB')
QGraphixcsView属性
DragMode中国語の解釈:この属性は、マウスの左ボタンが押されたときにマウスをシーンにドラッグする動作を保持します。
このプロパティは、ユーザーがシーンの背景をクリックしてマウスをドラッグしたときに何が起こるかを定義します(たとえば、ハンドカーソルを使用してビューポートのコンテンツをスクロールしたり、ラバーバンドを使用して複数のアイテムを選択したりします)。デフォルト値のNoDragは何の操作も実行しません。
この動作は、どのアイテムによっても処理されないマウスクリックにのみ影響します。QGraphicsViewのサブクラスを作成し、mouseMoveEvent()を再実装することで、カスタム動作を定義できます。