[SOLVED] How to disable a property:
-
Hi I am defining my own Qml Item in one file (Tile.qml) as like below.
Rectangle {
id : tile
width: 100
height: 100
color : "red"
property alias text : txt.text
property alias bgColor : tile.color
property alias fontColor : txt.color
property alias fontSize : txt.font.pixelSizeMouseArea { anchors.fill: parent onClicked: { console.log(txt.text); } } Text { id : txt anchors.centerIn: parent }
}
and using this user defined item multiple times in another file like this
Column
{
spacing : 5
Row
{
spacing: 5
Tile { id : obj11; text: "obj11"; bgColor : "red"; fontColor : "Yellow"}
Tile { id : obj12; text : "obj12"; bgColor : "red"; fontColor : "Black"}
Tile { id : obj13; text : "obj13"; bgColor : "red"; fontColor : "Black"}
}Row { spacing: 5 Tile { id : obj21; text: "obj21"; bgColor : "red"; fontColor : "Yellow"} Tile { id : obj22; text : "obj22"; bgColor : "red"; fontColor : "Black"} Tile { id : obj23; text : "obj23"; bgColor : "red"; fontColor : "Black"; width : 200} } }
Here I am actually using the tile item multiple places and able to make changes on any property.
But, I want to restrict the Tile width to 100 and height to 100 all the time. For that I want to disable these two properties so that they would not be accessible from outside. At the same time, I want to give control over all other properties.If I use nested Rectangle to define tile... in that case I supposed to do property alias for all other properties, that would be a over headache to me.
How can I achieve this, any help is highly appreciable.
-
Hello, please use code tag is much better to read :) I'm not sure but set properties private is not possible in qml. But you can register the change event on this properties and override the value every time.
-
Hi,
To add to dasRicardo's answer it is not possible for the built-in properties but for user-defined properties you can try "this":http://qt-project.org/doc/qt-4.8/qml-coding-conventions.html#private-properties way.
-
Please add [SOLVED] to thread title