Hi,

I have View class (inherited QGraphicsView) , Scene class and Element class (inherited QGraphicsItem)

DragMode is set to RubberBandDrag in the constructor of View class.

Element class is set to ItemIsMovable, ItemIsSelectable and does not have reimplemented mouse functions.

Qt Code:
  1. View::View(QWidget *parent) : QGraphicsView(parent)
  2. {
  3. setDragMode(QGraphicsView::RubberBandDrag);
  4. }
  5.  
  6.  
  7. void View::keyPressEvent(QKeyEvent *event){
  8.  
  9. if(scene()->focusItem() == NULL)
  10. if(event->key() == Qt::Key_Space )
  11. setDragMode(QGraphicsView::ScrollHandDrag);
  12.  
  13. QGraphicsView::keyPressEvent(event);
  14. }
  15.  
  16.  
  17. void View::keyReleaseEvent(QKeyEvent *event){
  18. if(event->key() == Qt::Key_Space)
  19. setDragMode(QGraphicsView::RubberBandDrag);
  20.  
  21. QGraphicsView::keyReleaseEvent(event);
  22. }
To copy to clipboard, switch view to plain text mode 

ScrollHandDrag works while space is pressed.

But after the space key released I can't move the items in the scene .
It draws a rubberband instead of moving the item.

If don't press&release the space key, I can draw a rubberband and move the selected items.

How can I solve this problem ?