I have this in my inherited GraphicsScene:
{
event->ignore();
// Reset selectionArea
// Always remember to call parents mousePressEvent
}
void MyGraphicsScene::mousePressEvent ( QGraphicsSceneMouseEvent * event )
{
event->ignore();
// Reset selectionArea
setSelectionArea(QPainterPath());
// Always remember to call parents mousePressEvent
QGraphicsScene::mousePressEvent(event);
}
To copy to clipboard, switch view to plain text mode
and
{
event->ignore();
bool ctrl = (event->modifiers() == Qt::ControlModifier);
if(tmpPath.isEmpty())
{
// if ctrl pressed, then toggle selection
emit select(event->scenePos(), ctrl);
}
else
{
// if ctrl pressed, then add selection
emit select(tmpPath, ctrl);
}
// Always remember to call parents mousePressEvent
}
void MyGraphicsScene::mouseReleaseEvent ( QGraphicsSceneMouseEvent * event )
{
event->ignore();
bool ctrl = (event->modifiers() == Qt::ControlModifier);
QPainterPath tmpPath = selectionArea();
if(tmpPath.isEmpty())
{
// if ctrl pressed, then toggle selection
emit select(event->scenePos(), ctrl);
}
else
{
// if ctrl pressed, then add selection
emit select(tmpPath, ctrl);
}
// Always remember to call parents mousePressEvent
QGraphicsScene::mouseReleaseEvent(event);
}
To copy to clipboard, switch view to plain text mode
I just inherited QGraphicsScene locally just to re-implement these two functions. This is the complete code I use in these two functions. You may not need all, but what I do, is to emit the signal with the path (selection rectangle) and if the user has pressed ctrl (adding elements)
Hope this helps and I didn't misunderstand your question.
Bookmarks