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. Declaring and setting the properties in a qml file.
Forum Updated to NodeBB v4.3 + New Features

Declaring and setting the properties in a qml file.

Scheduled Pinned Locked Moved Solved QML and Qt Quick
4 Posts 2 Posters 414 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.
  • A Offline
    A Offline
    Anita
    wrote on 21 Jun 2019, 10:25 last edited by Anita
    #1

    Hi,
    I am creating customised widgets that will be used in my application. So instead of exposing properties I will be setting the values of the
    properties via set Method.
    Ex:

    • MyWidget.qml
      Item{
      anchors.fill : parent
      QtObject{
      id:object
      property int rectWidth: 0
      }
      function setWidth(value)
      {
      object.rectWidth = value
      }
      Rectangle{
      width : object.rectWidth
      .
      }
      .
      .
      }
      -main.qml
      {
      MyWidget
      {
      width:100
      Component.onCompleted:
      {
      setWidth(20)
      }
      }
      }

    My query is: till the component creation is not completed the vital values would not be set. Am i right? and if we use the above approach will it have any disadvantage while setting up the properties of the widgets ?

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dheerendra
      Qt Champions 2022
      wrote on 21 Jun 2019, 12:29 last edited by
      #2

      Any reason for using the methods to set the values ? Unless objects are created you will not be able to set the values. It is is better to work with Properties rather than function which looks procedural programming.

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      2
      • A Offline
        A Offline
        Anita
        wrote on 24 Jun 2019, 05:35 last edited by
        #3

        @dheerendra ,

        We were starting with implementation, So having functions were decided and keeping the properties as private. But setting the properties of the file after the component is completed, will it work similar way for all the QML components such as RowLayout, ColumnLayout as well?

        As the RowLayout/ ColumnLayout will be used as a part of Model view and delegate, and all the properties of it (width, height,preferred height etc) will be set after the component is completed, so Will this also work in a similar way as setting up the properties?

        1 Reply Last reply
        0
        • D Offline
          D Offline
          dheerendra
          Qt Champions 2022
          wrote on 25 Jun 2019, 03:33 last edited by
          #4

          yes. It works as setting properties.

          Dheerendra
          @Community Service
          Certified Qt Specialist
          http://www.pthinks.com

          1 Reply Last reply
          0

          1/4

          21 Jun 2019, 10:25

          • Login

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