How to disable the automatic selectioning in a QGraphicsscene? [Solved]



  • Hi,

    when I put some QGraphicItems in a QGraphicsscene and give this Items the ItemIsSelectible flag, one item can be selected with a mouse click (all other items are deselected automatically then). If I hold down CTRL key while clicking, the other items hold their selection state. But how can I achive this with another key than CTRL or for example in a special mode, where I do not need to hold down a key for adding items to the selection with clicking on it. I tried nearly everything, but I do not know where to catch and avoid this automatic deselection behaviour. Does anyone know how this could be done?

    Thanks



  • Override the QGraphicsScene::mousePressEvent() and implement your own selection scheme. Have a look at the QGraphicsScene::mousePressEvent() implementation for ideas.



  • I tried this but it does not work, even if I do not propagate the mousePressEvent to QGraphicsScene::mousePressEvent() the deselection occurs. :(



  • OK, found it. The item itself does the selectioning and unselectioning in both it's mousePressEvent and mouseReleaseEvent. QGraphicsScene::mousePressEvent() does only a deselection of all items if there is no item under the cursor. So finally reimplementing QGraphicsItem::mousePressEvent() (and mouseReleaseEvent) and not propagate the event to the base class solved the problem.
    It is worthwhile to have a look at the source of QGraphicsItem::mousePressEvent().


  • Moderators

    Be sure and edit the title of your post to add [Solved]. Thanks!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.