mirror of
https://github.com/wassname/sloth.git
synced 2026-06-27 19:48:56 +08:00
allow rects to be moved by keyboard
This commit is contained in:
@@ -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
|
||||
=================================
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user