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. Does QML posses this QMl type logic?
Forum Updated to NodeBB v4.3 + New Features

Does QML posses this QMl type logic?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
5 Posts 2 Posters 383 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.
  • C Offline
    C Offline
    Circuits
    wrote on last edited by Circuits
    #1

    I am wondering is there anything in QMl that behaves like the following thing I am calling "elementX":

    elementX
    {
      id: thisElement
      listOfElementValues
      {
         value: x
         label: y
         foo: qsTr("Bar")
      }
    }
    

    such that I can now access those properties like so:

    onClicked: 
    {
      if(thisElement.foo === "Bar")
      {
        //do some logic
      }
    }
    
    1 Reply Last reply
    0
    • fcarneyF Offline
      fcarneyF Offline
      fcarney
      wrote on last edited by
      #2

      ListView
      Also, doing qsTr on the value that gets stored in foo will cause your comparison to fail unless you do:

      if(thisElement.foo === qsTr("Bar"))
      

      Or, only do qsTr on values that will be displayed and not values used in logic.

      C++ is a perfectly valid school of magic.

      C 1 Reply Last reply
      0
      • fcarneyF fcarney

        ListView
        Also, doing qsTr on the value that gets stored in foo will cause your comparison to fail unless you do:

        if(thisElement.foo === qsTr("Bar"))
        

        Or, only do qsTr on values that will be displayed and not values used in logic.

        C Offline
        C Offline
        Circuits
        wrote on last edited by Circuits
        #3

        @fcarney I am not sure I understand how this will work. Perhaps I just don't know what I am doing. Can I pass around the id of "elementX" for instance, to a component?

        What I have is a function which I am calling. The function will create a separate component and I want to be able to pass the model into that component, for instance:

        ListModel
        {
          id: myModel
        
          ListElement
          {
            value: 3
            unit: "ft"
            minValue: 0
            maxValue: 100
            label: "Label"
          }
        }
        
        onClicked:
        {
          //the component
          showNumericKeyboard("someString", [qsTr("Cancel"), qsTr("Finished")], myModel);
        }
        

        Now, in the showNumericKeyboard component I would like to have access to: value, unit, etc... I am not sure how I can do that s/t I can use those properties of myModel like to display a value to the user or what-have-you. So in the keypad component:

        TextStyled
        {
          id: idHeaderText
          anchors.fill: parent
          style: control.style.styleTextHeader
          wrapMode: Text.WordWrap
          text: myModel.label
        }
        
        1 Reply Last reply
        0
        • fcarneyF Offline
          fcarneyF Offline
          fcarney
          wrote on last edited by
          #4
          ListView {
              width: 180; height: 500
          
              model: myModel
              delegate: Text {
                  text: label + ": " + value + " " + unit
              }
          
             MouseArea {
                 onClicked: {
                     // stuff
                 }
             }
          }
          

          The delegate is where you do something for each item in the list. Are you looking for multiple objects or just one? Maybe QtObject is what you want:

              QtObject {
                  id: obj
                  property int value: 3
                  // other vars
              }
          

          C++ is a perfectly valid school of magic.

          C 1 Reply Last reply
          1
          • fcarneyF fcarney
            ListView {
                width: 180; height: 500
            
                model: myModel
                delegate: Text {
                    text: label + ": " + value + " " + unit
                }
            
               MouseArea {
                   onClicked: {
                       // stuff
                   }
               }
            }
            

            The delegate is where you do something for each item in the list. Are you looking for multiple objects or just one? Maybe QtObject is what you want:

                QtObject {
                    id: obj
                    property int value: 3
                    // other vars
                }
            
            C Offline
            C Offline
            Circuits
            wrote on last edited by
            #5

            @fcarney Yes, that's it! That's exactly what I was looking for, thank you!

            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