Skip to content

QQuickItem: Fix effective visibility for items without parent

Items are visible if they are children of a visible parent, and not explicitly hidden. The effectiveVisible member stores the state and is updated when conditions that impact the item visibility changes.

The old code returned true for items outside a visual hierarchy, which broke signal emission when items were removed from a parent, e.g. because the parent got destroyed. With this change, items removed from a visual hierarchy will emit the visibleChanged signal.

Note: QQuickItem initializes the effectiveVisible member to true, even if the item was created without parent item. Visual items are required to be added to a visual hierarchy via setParentItem. For this reason, newly created items never emit visibleChanged when they are added to a parent.

Adjust the QQuickItem::visible test - it creates an item hierarchy without window. Such items are never visible, so add a window and parent the test item hierarchy to the window's content item.

This fixes the expected failures in the tests. It does introduce an incompatibility with QGraphicsView and QGraphicsItem, which continue to return true from QGraphicsItem::isVisible for items that are not in an item hierarchy.

[ChangeLog][Qt Quick][QQuickItem] The visible property of Items without a parent now always returns false, and the visibleChanged signal gets emitted when the parent item of a visible item becomes null.

Fixes: QTBUG-108213 Change-Id: If4b2947cefd1407853f0f29e6c3fdbd49fc9af65 Reviewed-by: Fabian Kosmale fabian.kosmale@qt.io Reviewed-by: Shawn Rutledge shawn.rutledge@qt.io (cherry picked from commit d1b9a4ca)

CCBUG: 467909 CCBUG: 396359

Edited by Fushan Wen

Merge request reports