Is it possible to "lock" selection in Qt graphics view, to make clicks noneffective?
My scene can currently be in different states, and in some states selection should not change even if click happens.
Is it possible to "lock" selection in Qt graphics view, to make clicks noneffective?
My scene can currently be in different states, and in some states selection should not change even if click happens.
Reimplement the mousePressEvent(..)
in the views connected to the scene to ignore events.
void MyView::mousePressEvent(QMouseEvent* event)
{
if ( ignoreClickFlag && ( dragMode() == QGraphicsView::RubberBandDrag ||
items( event->pos() ).size() ) ) {
event->accept();
return;
}
QGraphicsView::mousePressEvent( event );
}
MyView::ignoreClickFlag
is a just a bool member that you can set in a slot.
So if the ignore mode is on, and the view is in rubber band drag mode and/or there is a node under the cursor, the click will be ignored. Another way to put it is, clicking is ignored if the user can perform a selection drag and/or if there is a item under the cursor, but not if the view is in pan drag mode and there is no item under the cursor.