PDA

View Full Version : QGraphicsScene and Extended Selection of items



totem
6th May 2010, 17:32
I'm stuck with the following problem :

I have a scene with several QGraphicsItems-derived instances. I make a first selection, then I want to extend it using CTRL-key and rubber band. The problem is that QGraphicsView does not seem to support extended selection due to following code :

in qgraphicsview.cpp :


void QGraphicsView::mousePressEvent(QMouseEvent *event)
{

// ...

#ifndef QT_NO_RUBBERBAND
if (d->dragMode == QGraphicsView::RubberBandDrag && !d->rubberBanding) {
if (d->sceneInteractionAllowed) {
// Rubberbanding is only allowed in interactive mode.
event->accept();
d->rubberBanding = true;
d->rubberBandRect = QRect();
if (d->scene) {
// Initiating a rubber band always clears the selection.
d->scene->clearSelection();
}
}
} else
#endif

// ...
}

As you see, "Initiating a rubber band always clears the selection". So I tried to overload my scene's clearSelection() method to have my word on it, but unfortunately it's not a virtual method and thus it's not called.

I'd prefer a check at scene's level, not at item's level (indeed, i could check for QApplication::keyboardModifiers() in the itemChange() method of each item, but it's kinda intrusive)

Anybody faced the same problem ?

Thanks in advance for your answers

aamer4yu
7th May 2010, 05:56
but u can override mousePressEvent ,,, cant you ?

totem
7th May 2010, 08:37
Do you mean i should copy the contents of QGraphicsView::mousePressEvent() in my custom View ?
I'm afraid I can't access the private part of the view, the one obtained using Q_D()... And thus not able to initialize rubber band

I will try and let you know, thank you for your idea