PDA

View Full Version : RubberBandDrag avoids selecting QGraphicsItem in the scene



barisatamer
5th February 2011, 04:15
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.



View::View(QWidget *parent) : QGraphicsView(parent)
{
setDragMode(QGraphicsView::RubberBandDrag);
}


void View::keyPressEvent(QKeyEvent *event){

if(scene()->focusItem() == NULL)
if(event->key() == Qt::Key_Space )
setDragMode(QGraphicsView::ScrollHandDrag);

QGraphicsView::keyPressEvent(event);
}


void View::keyReleaseEvent(QKeyEvent *event){
if(event->key() == Qt::Key_Space)
setDragMode(QGraphicsView::RubberBandDrag);

QGraphicsView::keyReleaseEvent(event);
}


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 ?