Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qquickwindowattached.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qquickwindow.h"
5#include "qquickitem.h"
7
9
10// QDoc comments must go in qquickwindow.cpp to avoid overwriting the Window docs
11
13 : QObject(attachee)
14 , m_window(nullptr)
15{
16 m_attachee = qobject_cast<QQuickItem*>(attachee);
17 if (m_attachee && m_attachee->window()) // It might not be in a window yet
18 windowChange(m_attachee->window());
19 if (m_attachee)
20 connect(m_attachee, &QQuickItem::windowChanged, this, &QQuickWindowAttached::windowChange);
21}
22
23QWindow::Visibility QQuickWindowAttached::visibility() const
24{
25 return (m_window ? m_window->visibility() : QWindow::Hidden);
26}
27
29{
30 return (m_window ? m_window->isActive() : false);
31}
32
34{
35 return (m_window ? m_window->activeFocusItem() : nullptr);
36}
37
39{
40 return (m_window ? m_window->contentItem() : nullptr);
41}
42
44{
45 return (m_window ? m_window->width() : 0);
46}
47
49{
50 return (m_window ? m_window->height() : 0);
51}
52
54{
55 return m_window;
56}
57
59{
60 if (window != m_window) {
61 QQuickWindow* oldWindow = m_window;
62 m_window = window;
63
64 if (oldWindow)
65 oldWindow->disconnect(this);
66
68
69 if (!oldWindow || !window || window->visibility() != oldWindow->visibility())
71 if (!oldWindow || !window || window->isActive() != oldWindow->isActive())
73 if (!oldWindow || !window || window->activeFocusItem() != oldWindow->activeFocusItem())
76 if (!oldWindow || !window || window->width() != oldWindow->width())
78 if (!oldWindow || !window || window->height() != oldWindow->height())
80
81 if (!window)
82 return;
83
84 // QQuickWindowQmlImpl::visibilityChanged also exists, and window might even
85 // be QQuickWindowQmlImpl, but that's not what we are connecting to.
86 // So this is actual window state rather than a buffered or as-requested one.
87 // If we used the metaobject connect syntax there would be a warning:
88 // QMetaObjectPrivate::indexOfSignalRelative - QMetaObject::indexOfSignal:
89 // signal visibilityChanged(QWindow::Visibility) from QQuickWindow redefined in QQuickWindowQmlImpl
90 connect(window, &QQuickWindow::visibilityChanged,
92 connect(window, &QQuickWindow::activeChanged,
94 connect(window, &QQuickWindow::activeFocusItemChanged,
100 }
101}
102
104
105#include "moc_qquickwindowattached_p.cpp"
\inmodule QtCore
Definition qobject.h:103
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2960
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
\threadsafe
Definition qobject.cpp:3236
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
Definition qquickitem.h:63
QQuickWindow * window() const
Returns the window in which this item is rendered.
QWindow::Visibility visibility
QQuickWindowAttached(QObject *attachee)
void windowChange(QQuickWindow *)
\qmltype Window \instantiates QQuickWindow \inqmlmodule QtQuick
QQuickItem * contentItem
\qmlattachedproperty Item Window::contentItem
QQuickItem * activeFocusItem
The item which currently has active focus or null if there is no item with active focus.
void heightChanged(int arg)
int width
the width of the window's geometry
Definition qwindow.h:82
Visibility visibility
the screen-occupation state of the window
Definition qwindow.h:93
void widthChanged(int arg)
int height
the height of the window's geometry
Definition qwindow.h:83
Combined button and popup list for selecting options.
QQuickItem * qobject_cast< QQuickItem * >(QObject *o)
Definition qquickitem.h:492
#define emit
QObject::connect nullptr
aWidget window() -> setWindowTitle("New Window Title")
[2]