diff options
Diffstat (limited to 'src/quick/items/qquickpaletteproviderprivatebase_p.h')
-rw-r--r-- | src/quick/items/qquickpaletteproviderprivatebase_p.h | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/src/quick/items/qquickpaletteproviderprivatebase_p.h b/src/quick/items/qquickpaletteproviderprivatebase_p.h index a0e0302ea9..869e86c954 100644 --- a/src/quick/items/qquickpaletteproviderprivatebase_p.h +++ b/src/quick/items/qquickpaletteproviderprivatebase_p.h @@ -221,7 +221,7 @@ void QQuickPaletteProviderPrivateBase<I, Impl>::registerPalette(PalettePtr palet // In order to avoid extra noise, we should connect // the following signals only after everything is already setup I::connect(paletteData(), &QQuickPalette::changed, itemWithPalette(), &I::paletteChanged); - I::connect(paletteData(), &QQuickPalette::changed, [this]{ updateChildrenPalettes(toQPalette()); }); + I::connect(paletteData(), &QQuickPalette::changed, itemWithPalette(), [this]{ updateChildrenPalettes(toQPalette()); }); } template<class T> struct dependent_false : std::false_type {}; @@ -230,9 +230,9 @@ template<class Impl, class I> decltype(auto) getPrivateImpl(I &t) { return Impl: template <class T> decltype(auto) getPrivate(T &item) { - if constexpr (std::is_same_v<T, QQuickWindow>) { + if constexpr (std::is_base_of_v<T, QQuickWindow>) { return getPrivateImpl<QQuickWindowPrivate>(item); - } else if constexpr (std::is_same_v<T, QQuickItem>) { + } else if constexpr (std::is_base_of_v<T, QQuickItem>) { return getPrivateImpl<QQuickItemPrivate>(item); } else { static_assert (dependent_false<T>::value, "Extend please."); @@ -257,12 +257,15 @@ template<class I, class Impl> QPalette QQuickPaletteProviderPrivateBase<I, Impl>::parentPalette(const QPalette &fallbackPalette) const { if constexpr (!isRootWindow<I>()) { - for (auto parentItem = itemWithPalette()->parentItem(); parentItem; - parentItem = parentItem->parentItem()) { - - // Don't allocate a new palette here. Use only if it's already pre allocated - if (parentItem && getPrivate(*parentItem)->providesPalette()) { - return getPrivate(*parentItem)->palette()->toQPalette(); + // Popups should always inherit from their window, even child popups: QTBUG-115707. + if (!std::is_base_of_v<QQuickPopup, I>) { + for (auto parentItem = itemWithPalette()->parentItem(); parentItem; + parentItem = parentItem->parentItem()) { + + // Don't allocate a new palette here. Use only if it's already pre allocated + if (parentItem && getPrivate(*parentItem)->providesPalette()) { + return getPrivate(*parentItem)->palette()->toQPalette(); + } } } @@ -279,7 +282,7 @@ const QQuickItem* rootItem(const I &item) { if constexpr (isRootWindow<I>()) { return item.contentItem(); - } else if constexpr (std::is_same_v<QQuickPopup, I>) { + } else if constexpr (std::is_base_of_v<QQuickPopup, I>) { return nullptr; } else { return &item; @@ -342,9 +345,12 @@ void QQuickPaletteProviderPrivateBase<I, Impl>::connectItem() if constexpr (!isRootWindow<I>()) { // Item with palette has the same lifetime as its implementation that inherits this class - I::connect(itemWithPalette(), &I::parentChanged , [this]() { inheritPalette(parentPalette(defaultPalette())); }); - I::connect(itemWithPalette(), &I::windowChanged , [this]() { inheritPalette(parentPalette(defaultPalette())); }); - I::connect(itemWithPalette(), &I::enabledChanged, [this]() { setCurrentColorGroup(); }); + I::connect(itemWithPalette(), &I::parentChanged, + itemWithPalette(), [this]() { inheritPalette(parentPalette(defaultPalette())); }); + I::connect(itemWithPalette(), &I::windowChanged, + itemWithPalette(), [this]() { inheritPalette(parentPalette(defaultPalette())); }); + I::connect(itemWithPalette(), &I::enabledChanged, + itemWithPalette(), [this]() { setCurrentColorGroup(); }); } } |