Pass thru properties?
-
Is this what you want?
https://stackoverflow.com/questions/26733011/how-to-declare-list-property-in-qml -
Is this what you want?
https://stackoverflow.com/questions/26733011/how-to-declare-list-property-in-qml@JoeCFD , not sure, its a work in progress this is what I have so far, StaleDataModel.qml:
import QtQuick 2.0 Item { id: root property bool initialised : false property string text: "N/A" property string color: "#777777" Text { text: root.text color: root.color font.pointSize: parent.width < 150 ? 30 : 16 horizontalAlignment: Text.AlignRight verticalAlignment: Text.AlignTop } }Ignore the properties that I've created already, what I want to do is allow any QML that includes an instance of StaleDataModel to be able to access any properties the Text control and any properties of any other object that I might include without having to expose every single property. I plan to add an Image to the file.
-
Is it possible to add an id to Text and then add functions in Item root to get any property of Text or Image?
@JoeCFD , Yes I can add an id to the Text, in fact I have already:
import QtQuick 2.0 Item { id: root property string color: "#777777" property string text: "N/A" Text { id: rText text: root.text font.pointSize: parent.width < 150 ? 30 : 16 horizontalAlignment: Text.AlignRight verticalAlignment: Text.AlignTop } property var anchors: rText.anchors property var color: tText.color }Still playing with it. So far no luck.
Example of what I'd like to do:
StaleDataModel { id:hdgValue rText.anchors.top: parent.top rText.color: '#ff0000' rText.width: 256 }However this doesn't work.
-
@JoeCFD , I can achieve the same as that by defining a property for the text color, but thats not what I want. I would like to be able to access any text attribute / property without having to write a property or function for every single property / attribute.
-
-
If you only want to extend the "Text" item, why don't you use it as root item in your qml file?
You don't have to wrap everything with an Item.// StaleDataModel.qml import QtQuick 2.0 // use Text als root item, so all default properties of Text will be available automatically Text { // define it somehow generic, so you can reuse the item with different settings property int fontSizeBreakPoint: 150 property int largeFontSize: 30 property int smallFontSize: 16 property color defaultColor: "#777777" color: defaultColor font.pointSize: parent.width < fontSizeBreakPoint ? largeFontSize : smallFontSize horizontalAlignment: Text.AlignRight verticalAlignment: Text.AlignTop }// SomeOther.qml StaleDataModel{ anchors.top: parent.top color: "#ff0000" text: "someText" } -
If you only want to extend the "Text" item, why don't you use it as root item in your qml file?
You don't have to wrap everything with an Item.// StaleDataModel.qml import QtQuick 2.0 // use Text als root item, so all default properties of Text will be available automatically Text { // define it somehow generic, so you can reuse the item with different settings property int fontSizeBreakPoint: 150 property int largeFontSize: 30 property int smallFontSize: 16 property color defaultColor: "#777777" color: defaultColor font.pointSize: parent.width < fontSizeBreakPoint ? largeFontSize : smallFontSize horizontalAlignment: Text.AlignRight verticalAlignment: Text.AlignTop }// SomeOther.qml StaleDataModel{ anchors.top: parent.top color: "#ff0000" text: "someText" }