개정판 f94312a8
ImageViewer DefaultCommand 추가 - 마우스 휠버튼으로 줌, 스코릴링, 패닝 가능
DTI_PID/DTI_PID/Commands/DefaultCommand.py | ||
---|---|---|
1 | 1 |
import os.path |
2 | 2 |
import AbstractCommand |
3 | 3 |
try: |
4 |
from PyQt5.QtCore import Qt, QRectF, pyqtSignal, QT_VERSION_STR |
|
5 |
from PyQt5.QtGui import QImage, QPixmap, QPainterPath, QCursor |
|
4 |
from PyQt5.QtCore import Qt, QRectF, pyqtSignal, QT_VERSION_STR, QEvent
|
|
5 |
from PyQt5.QtGui import QImage, QPixmap, QPainterPath, QCursor, QMouseEvent
|
|
6 | 6 |
from PyQt5.QtWidgets import QGraphicsView, QGraphicsScene, QFileDialog |
7 | 7 |
except ImportError: |
8 | 8 |
try: |
9 |
from PyQt4.QtCore import Qt, QRectF, pyqtSignal, QT_VERSION_STR |
|
10 |
from PyQt4.QtGui import QGraphicsView, QGraphicsScene, QImge, QPixmap, QPainterPath, QFileDialog, QCursor |
|
9 |
from PyQt4.QtCore import Qt, QRectF, pyqtSignal, QT_VERSION_STR, QEvent
|
|
10 |
from PyQt4.QtGui import QGraphicsView, QGraphicsScene, QImge, QPixmap, QPainterPath, QFileDialog, QCursor, QMouseEvent
|
|
11 | 11 |
except ImportError: |
12 | 12 |
raise ImportError("ImageViewerQt: Requires PyQt5 or PyQt4.") |
13 | 13 |
|
... | ... | |
21 | 21 |
def __init__(self, imageViewer): |
22 | 22 |
super(DefaultCommand, self).__init__(imageViewer) |
23 | 23 |
self.name = 'Default' |
24 |
self.imageViewer.setCursor(QCursor(Qt.OpenHandCursor)) |
|
24 |
#self.imageViewer.setCursor(QCursor(Qt.OpenHandCursor))
|
|
25 | 25 |
|
26 | 26 |
''' |
27 | 27 |
@brief Scrol / Pan / Zoom with Wheel Button |
... | ... | |
33 | 33 |
event = param[1] |
34 | 34 |
scenePos = param[2] |
35 | 35 |
if 'mousePressEvent' == param[0] and event.button() == Qt.MiddleButton: |
36 |
print("Middle Button Pressed") |
|
37 |
#if self.imageViewer.canPan: |
|
38 | 36 |
self.imageViewer.setDragMode(QGraphicsView.ScrollHandDrag) |
39 |
|
|
40 |
self.imageViewer.midMouseButtonPressed.emit(scenePos.x(), scenePos.y()) |
|
41 |
#QGraphicsView.mousePressEvent(self.imageViewer, event) |
|
37 |
QGraphicsView.mousePressEvent(self.imageViewer, QMouseEvent(QEvent.MouseButtonPress, event.pos(), Qt.LeftButton, event.buttons(), Qt.NoModifier)) |
|
42 | 38 |
elif 'mouseReleaseEvent' == param[0] and event.button() == Qt.MiddleButton: |
43 |
print("Middle Button Released") |
|
44 | 39 |
try: |
45 | 40 |
self.imageViewer.setDragMode(QGraphicsView.NoDrag) |
46 | 41 |
finally: |
47 |
self.imageViewer.midMouseButtonReleased.emit(scenePos.x(), scenePos.y()) |
|
48 |
#QGraphicsView.mouseReleaseEvent(self.imageViewer, event) |
|
42 |
QGraphicsView.mouseReleaseEvent(self.imageViewer, QMouseEvent(QEvent.MouseButtonRelease, event.pos(), Qt.LeftButton, event.buttons(), Qt.NoModifier)) |
|
49 | 43 |
pass |
50 | 44 |
self.isTreated = False |
51 | 45 |
|
DTI_PID/DTI_PID/QtImageViewer.py | ||
---|---|---|
43 | 43 |
leftMouseButtonDoubleClicked = pyqtSignal(float, float) |
44 | 44 |
rightMouseButtonDoubleClicked = pyqtSignal(float, float) |
45 | 45 |
|
46 |
midMouseButtonPressed = pyqtSignal(float, float) |
|
47 |
midMouseButtonReleased = pyqtSignal(float, float) |
|
48 |
|
|
49 | 46 |
def __init__(self): |
50 | 47 |
QGraphicsView.__init__(self) |
51 | 48 |
|
내보내기 Unified diff