Solved property aus QtObject neu initialisieren (QML)
-
Hallo Zusammen,
folgende Datei habe ich:
QtObject { property QtObject darkBg: QtObject { readonly property color backgroundNormalColor: "green" readonly property color textNormalColor: "red" readonly property url normalImage: "" .... readonly property color backgroundSelectedColor: "yellow" readonly property color textSelectedColor: ... readonly property url selectedImage: "" readonly property int width: 50 readonly property int normalHeight: 45 readonly property int depressedHeight: 48 readonly property int contentDisplay: contentDisplayType.textOnly readonly property font font: ... } property QtObject lightBg: QtObject { ...... } property QtObject blueBg: QtObject { readonly property color textGhostedColor: "green" readonly property color focusFrameGhostedColor: "blue" } readonly property QtObject contentDisplayType: QtObject { property int textOnly : 0 // Display the text only property int imageOnly : 1 // Display the image only property int textAndImage : 2 // Display the text and the image } }
in diesen datei werde alle möglische Farben, was einen Button haben kann, definiert.
meine Frage: Wie kann ich z.b auf den font oder normalHeight um einen neue Value zuzuweisen?Danke
-
@Galilio da alle properties readonly sind, würd ich mal sagen, nein, du kannst du bei laufenden Betrieb nicht ändern.
-
@J-Hilk
danke für die Antwort.
Wenn ich den readonly weglasse, wie greife ich den auf einzelne Property?folgende habe ich versucht: wenn die Buttons einen lightBg haben sollen, dann habe ich folgende gemacht:
property QtObject buttonStyle: QQtButtonStyle.lightBg
aber wenn ich z.b nur den normalHeight neue Value zuweisen möchte: Wie tue ich das?
Danke
-
@J-Hilk
Wie kann ich bitte auf diese Property zugreifen?Danke in voraus
-
@Galilio tja, bin mir net sicher, ich nutze normalweise nicht die QML
property QtObject
Objekte, ich würde vermuten ganz normal:QQtButtonStyle.lightBg.normalHeight: 200
-
@J-Hilk
wenn ich so mache, dann bekomme ich diese Fehlermeldung:Non-existent attached object
-
wenn ich so was habe:
property QtObject buttonStyle: QQtButtonStyle.lightBg
dann versuche ich auf die Property in der QObject zugreifen (einfach auslesen) --> Das geht nicht Warum?
Ich bekomme die Fehlermeldung: Es sei:
Unable to assign [undefined] to QColor
Das verstehe ich nicht!!!
-
Um die Property neu zu initialisieren , müssen nicht readonly sein.
Zweiten man braucht einen Hilfsvariable von type QtObject um die Überschreibung zu ermöglischen.