Unsolved How to define a property of type 'palette'?
-
So, according to docs, palette is a basic type (and part of Qt Quick Controls): https://doc.qt.io/qt-5/qml-palette.html
How do I create a property of that type?
My attempt:
import QtQuick 2.15 import QtQuick.Controls 2.15 Item { property Palette dialogPalette: { base: "#222222" alternateBase: "#333333" } }
States that "Palette" is not a type.
Ok, true enough, in the docs, the basic type is written with lowercase "palette". But QML can't seem to handle lowercase type names.Any ideas?
-
palette { base: "#222222" alternateBase: "#333333" }
Or:
palette.base: "#222222" palette.alternateBase: "#333333"
So it works the same as
font
andanchors
do. -
@sierdzio
Interesting. Is that a non-visual component or a property? -
@Asperamanca
Ah, I think you misunderstood. I don't want to define the values of a component's existing palette property. I want to define a new palette property, e.g. to provide an interface to an outside QML file using my component.Because if I write the code as you posted, I get "Invalid property name 'palette'"
EDIT:
What does work is (EDIT2: No it doesn't: alternateBase is a read-only property in this case)property SystemPalette palette palette.base: "#222222" palette.alternateBase: "#333333"
...but I don't really understand the relation between "palette basic type" and "system palette basic type", except that the system palette gets it's colors from the QPalette defined with QApplication
-
@Asperamanca said in How to define a property of type 'palette'?:
Ah, I think you misunderstood. I don't want to define the values of a component's existing palette property. I want to define a new palette property, e
Ouch, you're right, I misunderstood :-( I don't know how to define it in a new component. Looking at the code, though, it seems to be "just" QPalette:
Q_PROPERTY(QPalette palette READ palette WRITE setPalette RESET resetPalette NOTIFY paletteChanged FINAL REVISION 3)
(https://code.woboq.org/qt5/qtquickcontrols2/src/quicktemplates2/qquickcontrol_p.h.html#QQuickControl)
And looking here: https://code.woboq.org/qt5/qtdeclarative/src/quick/util/qquicksystempalette.cpp.html it seems that the QML type is
SystemPalette
, like you have found. -
@sierdzio
Well, there does seem to be a separate "palette" type defined for Qt Quick ControlsSee https://doc.qt.io/qt-5/qml-palette.html
Vs https://doc.qt.io/qt-5/qml-qtquick-systempalette.htmlFor me, I want to pass a palette through my custom Component to the contained QML components.
-
@Asperamanca said in How to define a property of type 'palette'?:
For me, I want to pass a palette through my custom Component to the contained QML components.
Since it's a QObject, just to pass it through you can possibly use
var
orQtObject
types. Ugly but might just work. -
Appreciating this is an old ticket, I have acquired some pertinent updates.
Unfortunately Qt decided that QQuickWindow's QPalette property was going to be "upgraded" to QQuickPalette type which is not public (and it doesn't look like they want to make it either). There is currently no way to pass a QPalette from C++ into an ApplicationWindow's (or any other QQuickControl's) palette property. You have to work around it by setting every single palette group property:
https://doc.qt.io/qt-6/qml-qtquick-palette.html
You may also find SystemPalette useful to some extent if you set a QPalette on your QGuiApplication.
However take care: the following color roles are missing from SystemPalette API (and the documentation):
brightText >> https://bugreports.qt.io/browse/QTBUG-67557
link >> https://bugreports.qt.io/browse/QTBUG-53189
linkVisited >> (as above)
toolTipBase >> reported
toolTipText >> reportedOther referenced JIRA tickets:
https://bugreports.qt.io/browse/QTBUG-104040
https://bugreports.qt.io/browse/QTBUG-95591
https://bugreports.qt.io/browse/QTBUG-91365and also this posting:
https://lists.qt-project.org/pipermail/development/2020-August/040133.html