Access colors of a QPalette property
Solved
QML and Qt Quick
-
I have a C++ class which provides a QPalette as a property:
Q_PROPERTY(QPalette activePalette READ getActivePalette NOTIFY notifyActivePaletteChanged)
This class is registered in QML and can be called like so:
Text { color: style.activePalette.windowText text: "Some text" }
However, when I use style.activePalette.windowText, I get "Cannot read property 'windowText' of undefined"
My understanding was that a QPalette on the C++ side becomes a palette QML type on the QML side, and for this 'windowText' is defined as "palette.windowText : color - A general foreground color."
Any suggestions what goes wrong here?
-
For anyone with the same issue: The cause here seems to be name shadowing. See https://forum.qt.io/topic/74969/qml-how-to-access-context-property-if-its-name-is-shadowed-by-a-component-local-property