Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. [SOLVED] How to disable a property:
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] How to disable a property:

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 3 Posters 1.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    venkatatrins
    wrote on last edited by
    #1

    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.pixelSize

    MouseArea {
        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.

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dasRicardo
      wrote on last edited by
      #2

      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.

      **Sorry for my english :)

      PLEASE ADD [SOLVED] TO YOUR THREAD TITLE IF IT'S SOLVED.**

      1 Reply Last reply
      0
      • p3c0P Offline
        p3c0P Offline
        p3c0
        Moderators
        wrote on last edited by
        #3

        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.

        157

        1 Reply Last reply
        0
        • D Offline
          D Offline
          dasRicardo
          wrote on last edited by
          #4

          Please add [SOLVED] to thread title

          **Sorry for my english :)

          PLEASE ADD [SOLVED] TO YOUR THREAD TITLE IF IT'S SOLVED.**

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved