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

QDeclarativeItem::hasActiveFocus() can return true even for hidden items

    XMLWordPrintable

Details

    • a1b2be3c8a64aee832c648c6dcdff003f22318a3

    Description

      From the docs of QDeclarativeItem::activeFocus it seems that it only should return true if the item receives keyboard focus. However, by looking at the code this seems not to be the case, since focusItem() can return an item pointer if its hidden too. (in fact, I believe focusItem() is supposed to work the same way as focusWidget() works, but its documentation is not very clear on that - however the implementation indicates that)

      Found while looking into QTBUG-15047

      Suggested patch:

      diff --git a/src/declarative/graphicsitems/qdeclarativeitem.cpp b/src/declarative/graphicsitems/qdeclarativeitem.cpp
      index d36d163..b9d231e 100644
      --- a/src/declarative/graphicsitems/qdeclarativeitem.cpp
      +++ b/src/declarative/graphicsitems/qdeclarativeitem.cpp
      @@ -3600,8 +3600,8 @@ void QDeclarativeItem::setSize(const QSizeF &size)
       bool QDeclarativeItem::hasActiveFocus() const
       {
           Q_D(const QDeclarativeItem);
      -    return focusItem() == this ||
      -           (d->flags & QGraphicsItem::ItemIsFocusScope && focusItem() != 0);
      +    return (focusItem() && focusItem()->isVisible()) && (focusItem() == this ||
      +           (d->flags & QGraphicsItem::ItemIsFocusScope && focusItem() != 0));
       }
      
       /*!
      

      Attachments

        For Gerrit Dashboard: QTBUG-21045
        # Subject Branch Project Status CR V

        Activity

          People

            aalpert-nokia Alan Alpert (closed Nokia identity) (Inactive)
            smd Jan Arve
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes