pyqt4 - How can I move a QGraphicsItem using keyboard? -


hello need moving object in case qgraphicpixmapitem throw scene using keyboard. code have, method need add handle moving event?

thanks

class object(qtgui.qgraphicspixmapitem):     def __init__(self, parent=none):         qtgui.qgraphicspixmapitem.__init__(self, parent)         self.setflag(self.itemisfocusable, true)       def keypressevent(self, e):         if e.key() == qtcore.qt.key_right:             print('right')         elif e.key() == qtcore.qt.key_left:             print('left')         elif e.key() == qtcore.qt.key_down:             print('down')         elif e.key() == qtcore.qt.key_up:             print('up')      def keyreleaseevent(self, e):         pass   class scene(qtgui.qgraphicsscene):         def __init__(self, parent=none):             qtgui.qgraphicsscene.__init__(self, parent) 

modify position of qgraphicspixmapitem on keypressevent.

self.setpos(self.x()+my_x_offset, self.y()+my_y_offset) 

replace my_x_offset , my_y_offset appropriate numbers of choosing (for instance left key press might make my_x_offset=10 , my_y_offset=0)


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -