+/*!
+ \qmlattachedproperty Item Window::contentItem
+ \since 5.4
+
+ This attached property holds the invisible root item of the scene or
+ \c null if the item is not in a window. The Window attached property
+ can be attached to any Item.
+*/
/*!
\property QQuickWindow::contentItem
return (m_window ? m_window->activeFocusItem() : Q_NULLPTR);
}
+QQuickItem *QQuickWindowAttached::contentItem() const
+{
+ return (m_window ? m_window->contentItem() : Q_NULLPTR);
+}
+
void QQuickWindowAttached::windowChanged(QQuickWindow *window)
{
if (window != m_window) {
emit activeChanged();
if (!oldWindow || window->activeFocusItem() != oldWindow->activeFocusItem())
emit activeFocusItemChanged();
+ emit contentItemChanged();
// QQuickWindowQmlImpl::visibilityChanged also exists, and window might even
// be QQuickWindowQmlImpl, but that's not what we are connecting to.
Q_PROPERTY(QWindow::Visibility visibility READ visibility NOTIFY visibilityChanged)
Q_PROPERTY(bool active READ isActive NOTIFY activeChanged)
Q_PROPERTY(QQuickItem* activeFocusItem READ activeFocusItem NOTIFY activeFocusItemChanged)
+ Q_PROPERTY(QQuickItem* contentItem READ contentItem NOTIFY contentItemChanged)
public:
QQuickWindowAttached(QObject* attachee);
QWindow::Visibility visibility() const;
bool isActive() const;
QQuickItem* activeFocusItem() const;
+ QQuickItem* contentItem() const;
Q_SIGNALS:
void visibilityChanged();
void activeChanged();
void activeFocusItemChanged();
+ void contentItemChanged();
protected Q_SLOTS:
void windowChanged(QQuickWindow*);
width: 100
height: 100
property bool windowActive: root.Window.active
+ property Item contentItem: root.Window.contentItem
Text {
objectName: "rectangleWindowText"
anchors.centerIn: parent
objectName: "extraWindowText"
anchors.centerIn: parent
text: (extraWindow.active ? "active" : "inactive") + "\nvisibility: " + Window.visibility
+ property Item contentItem: Window.contentItem
}
}
}
view.requestActivate();
QVERIFY(QTest::qWaitForWindowActive(&view));
QVERIFY(view.rootObject()->property("windowActive").toBool());
+ QCOMPARE(view.rootObject()->property("contentItem").value<QQuickItem*>(), view.contentItem());
QQuickWindow *innerWindow = view.rootObject()->findChild<QQuickWindow*>("extraWindow");
QVERIFY(innerWindow);
QQuickText *text = view.rootObject()->findChild<QQuickText*>("extraWindowText");
QVERIFY(text);
QCOMPARE(text->text(), QLatin1String("active\nvisibility: 2"));
+ QCOMPARE(text->property("contentItem").value<QQuickItem*>(), innerWindow->contentItem());
}
class RenderJob : public QRunnable