Important: Please read the Qt Code of Conduct -

[Solved] Check click outside QGraphicsItem parent and child

  • Hi all

    I need to have one main QGraphicsItem always showed and another children QGraphicsItem showed for particular event. I want this secondary child QGraphicsItem to hide automatically if user click in the scene out from the secondary child QGraphicsItem and out from the parent main QGraphicsItem (basically out of both). Currently I'm trying to hide the secondary child item based to the focusout event but doesn't work since this event is generated also if I click over the parent item always visible. Currently I'm still not able to found a solution...

    Someone have a suggestion regarding how to fix this problem?

    Thank you

  • Lifetime Qt Champion


    Just a quick idea but what about using installSceneEventFilter and check there where you cursor can be found when the focusOut event occurs ?

    Hope it helps

  • Hi

    Thank you for your reply. Indeed I already tried the installSceneEventFilter way but the problem is not easy to know the next will have focus. Basically the sequence is to send the focusout event to the item will going to loose the focus and then set the focus to the next item will going to get. This mean when the item will receive the focus out event is not possible to knwo who will be the next since not yes "assigned". This, obviously, at item level, scene or view have the focus event passing the two items who will loose and get the focus...

  • Hi again

    Just found a solution based to what I wrote before :). Simply I connect to the focusItemChanged scene signal from inside my child item. Using this way I can know who will receive new item. If is different from child a parent item I'll close the chils and disconnect from signal. Easy and working.

  • Lifetime Qt Champion

    Nice !

    Thanks for sharing your solution :)

Log in to reply