diff options
author | Jan Arve Sæther <jan-arve.saether@qt.io> | 2020-12-15 17:45:23 +0100 |
---|---|---|
committer | Jan Arve Sæther <jan-arve.saether@qt.io> | 2020-12-16 10:40:42 +0100 |
commit | 8166660e38c7b56316193ca2eb20b95dfa5fa7f5 (patch) | |
tree | 98ecc9746e903708d45e16d8f7f8a3c36daadae6 /src | |
parent | 544fe3dcf5ce1f539c9d74ac23815268950b9212 (diff) |
Only connect to the items window signals if it has a window
If the styleitem was created in a control without a window, it
failed to connect to the activeChanged() signal of QQuickWindow.
It would consequently warn about invalid null parameter to
QObject::connect()
If the control was added to a window at a later point, it would also
not connect to the activeChanged() signal of QQuickWindow. This could
cause that the control was rendered as it would be rendered in an
inactive window, even if the window actually was active.
Task-number: QTBUG-88553
Pick-to: 6.0
Change-Id: I3aa5948e150f0f4baa204943ec43ea8922421e75
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/imports/nativestyle/items/qquickstyleitem.cpp | 16 | ||||
-rw-r--r-- | src/imports/nativestyle/items/qquickstyleitem.h | 1 |
2 files changed, 15 insertions, 2 deletions
diff --git a/src/imports/nativestyle/items/qquickstyleitem.cpp b/src/imports/nativestyle/items/qquickstyleitem.cpp index cabc6631..0cc94b42 100644 --- a/src/imports/nativestyle/items/qquickstyleitem.cpp +++ b/src/imports/nativestyle/items/qquickstyleitem.cpp @@ -113,8 +113,11 @@ void QQuickStyleItem::connectToControl() const { connect(m_control, &QQuickStyleItem::enabledChanged, this, &QQuickStyleItem::markImageDirty); connect(m_control, &QQuickItem::activeFocusChanged, this, &QQuickStyleItem::markImageDirty); - connect(m_control, &QQuickStyleItem::windowChanged, this, &QQuickStyleItem::markImageDirty); - connect(window(), &QQuickWindow::activeChanged, this, &QQuickStyleItem::markImageDirty); + + if (QQuickWindow *win = window()) { + connect(win, &QQuickWindow::activeChanged, this, &QQuickStyleItem::markImageDirty); + m_connectedWindow = win; + } } void QQuickStyleItem::markImageDirty() @@ -253,6 +256,15 @@ void QQuickStyleItem::itemChange(QQuickItem::ItemChange change, const QQuickItem if (data.boolValue) markImageDirty(); break; + case QQuickItem::ItemSceneChange: { + markImageDirty(); + QQuickWindow *win = data.window; + if (m_connectedWindow) + disconnect(m_connectedWindow, &QQuickWindow::activeChanged, this, &QQuickStyleItem::markImageDirty); + if (win) + connect(win, &QQuickWindow::activeChanged, this, &QQuickStyleItem::markImageDirty); + m_connectedWindow = win; + break;} default: break; } diff --git a/src/imports/nativestyle/items/qquickstyleitem.h b/src/imports/nativestyle/items/qquickstyleitem.h index 0a89454b..e262055f 100644 --- a/src/imports/nativestyle/items/qquickstyleitem.h +++ b/src/imports/nativestyle/items/qquickstyleitem.h @@ -285,6 +285,7 @@ private: DirtyFlags m_dirty = Everything; bool m_useNinePatchImage = true; bool m_polishing = false; + mutable QQuickWindow *m_connectedWindow = nullptr; #ifdef Q_OS_MACOS int m_transitionDuration = 150; |