allow rects to be moved by keyboard

This commit is contained in:
Martin Baeuml
2011-05-19 12:38:18 +02:00
parent a72fe37bcf
commit e2df6dd7e0
2 changed files with 25 additions and 0 deletions
+8
View File
@@ -46,6 +46,14 @@ created rectangles, maybe even different kinds for different label types::
"head" : GreenRectItem,
}
items.RectItem
==============
Usage:
* Can be moved by Left/Right/Up/Down keys. If Shift is pressed, step is increased. If Control is pressed,
width and height are modified instead of position.
Write your own visualization item
=================================
+17
View File
@@ -171,6 +171,23 @@ class RectItem(AnnotationGraphicsItem):
self._updateRect(rect)
self._updateText()
def keyPressEvent(self, event):
step = 1
if event.modifiers() & Qt.ShiftModifier:
step = 5
ds = { Qt.Key_Left: (-step, 0),
Qt.Key_Right: (step, 0),
Qt.Key_Up: (0, -step),
Qt.Key_Down: (0, step),
}.get(event.key(), None)
if ds is not None:
if event.modifiers() & Qt.ControlModifier:
rect = self.rect_.adjusted(*((0, 0) + ds))
else:
rect = self.rect_.adjusted(*(ds + ds))
self._updateRect(rect)
event.accept()
class PointItem(AnnotationGraphicsItem):
def __init__(self, index, parent=None):
AnnotationGraphicsItem.__init__(self, index, parent)