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. setting arguments in reused QML file
Forum Updated to NodeBB v4.3 + New Features

setting arguments in reused QML file

Scheduled Pinned Locked Moved Solved QML and Qt Quick
6 Posts 2 Posters 503 Views 2 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.
  • mzimmersM Offline
    mzimmersM Offline
    mzimmers
    wrote on last edited by
    #1

    Hi all -

    I've looked through the docs, but didn't find quite what I wanted. I have a QML file (SortedTable.qml) that is used by several displays. I need to modify it so the parent can specify the widths of the columns.

    Currently, the column widths are formatted like this:

     property int cellWidth: width / (viewModel.header().length + extraCols_)
     property real cellStretch0: cellWidth * 1.7
     property real cellStretch1: cellWidth * 0.4
     property real cellStretch2: cellWidth * 0.9
     property real cellStretch3: cellWidth
     property variant columnWidths: [cellStretch0, cellStretch1, cellStretch2, cellStretch3]
    

    And the property columnWidths is used in various places in SortedTable.

    I'd like to move the cellStretchN definitions out of SortedTable, into the parent files, but have a default value for them in SortedTable. I'm sure this can be done, but I need a pointer on how.

    Thanks...

    ODБOïO 1 Reply Last reply
    0
    • mzimmersM mzimmers

      Hi all -

      I've looked through the docs, but didn't find quite what I wanted. I have a QML file (SortedTable.qml) that is used by several displays. I need to modify it so the parent can specify the widths of the columns.

      Currently, the column widths are formatted like this:

       property int cellWidth: width / (viewModel.header().length + extraCols_)
       property real cellStretch0: cellWidth * 1.7
       property real cellStretch1: cellWidth * 0.4
       property real cellStretch2: cellWidth * 0.9
       property real cellStretch3: cellWidth
       property variant columnWidths: [cellStretch0, cellStretch1, cellStretch2, cellStretch3]
      

      And the property columnWidths is used in various places in SortedTable.

      I'd like to move the cellStretchN definitions out of SortedTable, into the parent files, but have a default value for them in SortedTable. I'm sure this can be done, but I need a pointer on how.

      Thanks...

      ODБOïO Offline
      ODБOïO Offline
      ODБOï
      wrote on last edited by ODБOï
      #2

      hi @mzimmers
      If i understand the question correctly, there is nothig special to do here, you can let whatever default value in Sorted Table.qml and then reassign that value when you create SortedTable components

      mzimmersM 1 Reply Last reply
      0
      • ODБOïO ODБOï

        hi @mzimmers
        If i understand the question correctly, there is nothig special to do here, you can let whatever default value in Sorted Table.qml and then reassign that value when you create SortedTable components

        mzimmersM Offline
        mzimmersM Offline
        mzimmers
        wrote on last edited by
        #3

        @LeLev here's what I tried:

        SortedTable.qml:

        Item {
          id: root
          property int cellWidth: width / (viewModel.header().length + extraCols_)
          property real cellStretch0: cellWidth
          property real cellStretch1: cellWidth
          property real cellStretch2: cellWidth
          property real cellStretch3: cellWidth
        

        and in the parent:

          SortedTable {
              property real cellStretch0: cellWidth * 1.7
              property real cellStretch1: cellWidth * 0.4
              property real cellStretch2: cellWidth * 0.9
              property real cellStretch3: cellWidth
        

        but it doesn't "take" (the values in the parent aren't used).

        ODБOïO 1 Reply Last reply
        0
        • mzimmersM mzimmers

          @LeLev here's what I tried:

          SortedTable.qml:

          Item {
            id: root
            property int cellWidth: width / (viewModel.header().length + extraCols_)
            property real cellStretch0: cellWidth
            property real cellStretch1: cellWidth
            property real cellStretch2: cellWidth
            property real cellStretch3: cellWidth
          

          and in the parent:

            SortedTable {
                property real cellStretch0: cellWidth * 1.7
                property real cellStretch1: cellWidth * 0.4
                property real cellStretch2: cellWidth * 0.9
                property real cellStretch3: cellWidth
          

          but it doesn't "take" (the values in the parent aren't used).

          ODБOïO Offline
          ODБOïO Offline
          ODБOï
          wrote on last edited by ODБOï
          #4

          @mzimmers said in setting arguments in reused QML file:

          SortedTable {
          property real cellStretch0: cellWidth * 1.7

          you are re-declaring the properties, you just need to assing the new values like this

          SortedTable {
                cellStretch0: cellWidth * 1.7
               cellStretch1: cellWidth * 0.4
          

          but i'm not sure columnWidths will be updated in the component, you might need to reassign it

          mzimmersM 1 Reply Last reply
          4
          • ODБOïO ODБOï

            @mzimmers said in setting arguments in reused QML file:

            SortedTable {
            property real cellStretch0: cellWidth * 1.7

            you are re-declaring the properties, you just need to assing the new values like this

            SortedTable {
                  cellStretch0: cellWidth * 1.7
                 cellStretch1: cellWidth * 0.4
            

            but i'm not sure columnWidths will be updated in the component, you might need to reassign it

            mzimmersM Offline
            mzimmersM Offline
            mzimmers
            wrote on last edited by
            #5

            @LeLev thank you! This works fine. And the array does indeed update -- I guess it's created on-the-fly when the screen is invoked.

            Thanks again for the help.

            ODБOïO 1 Reply Last reply
            1
            • mzimmersM mzimmers

              @LeLev thank you! This works fine. And the array does indeed update -- I guess it's created on-the-fly when the screen is invoked.

              Thanks again for the help.

              ODБOïO Offline
              ODБOïO Offline
              ODБOï
              wrote on last edited by ODБOï
              #6

              @mzimmers You're welcome :)
              BTW "variant" qml type is obsolete. If possible, you should use "var" instead
              see here https://doc.qt.io/qt-5/qml-variant.html

              1 Reply Last reply
              1

              • Login

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