Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-85728

Cannot retrieve focused item from QGraphicsScene when it is active but does not have focus



    • Type: Bug
    • Status: Reported
    • Priority: P2: Important
    • Resolution: Unresolved
    • Affects Version/s: 5.15.0
    • Fix Version/s: None
    • Component/s: Widgets: GraphicsView
    • Labels:
    • Platform/s:


      I have a Windows application that has a QGraphicsView as its only main view. From what I can tell, the scene is only inactive when the application itself is not active. When clicking into another widget, the scene loses focus, and I have no way to get at the item that had focus, because QGraphicsScene::focusItem() returns NULL, yet the passive focus item is set to the item I would like to have.

      The QGraphicsScene has the following documentation:

      If the scene loses focus, (i.e.,
      someone calls clearFocus()) while an item has focus, the scene will
      maintain its item focus information, and once the scene regains focus, it
      will make sure the last focus item regains focus.

      It maintains that focused item via its passiveFocusItem member when the scene loses focus, for example, via a clearFocus() call.

      However QGraphicsScene::focusItem() only returns the focusItem member if the scene is active, and returns the passiveFocusItem member if the scene is not active. I believe that it should instead return the focusItem member if the scene has focus, and return the passiveFocusItem member if the scene does not have focus. In other words, I believe the isActive() call in QGraphicsScene::focusItem() should be changed to an hasFocus() call.


        No reviews matched the request. Check your Options in the drop-down menu of this sections header.



            bibr Andreas Aardal Hanssen
            avautour André Vautour
            0 Vote for this issue
            1 Start watching this issue



                Gerrit Reviews

                There are no open Gerrit changes