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. ComboBox list pass to Qt
Forum Updated to NodeBB v4.3 + New Features

ComboBox list pass to Qt

Scheduled Pinned Locked Moved Solved QML and Qt Quick
4 Posts 3 Posters 301 Views
  • 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.
  • D Offline
    D Offline
    Damian7546
    wrote on last edited by Damian7546
    #1

    Hi,
    How can I call this function systemController.speedPrinting === selectedItemFromComboBox depending on select item from below combobox ?

    ColumnLayout {
            id: stacViewCombobox1
            width: 500
            anchors {
                left: parent.left
                leftMargin: 30
                top: textSettingPrinter.bottom
                topMargin: 30
            }
            ComboBox {
                id: mycombo
                Layout.fillWidth: true
                font.pointSize: 16
                 popup.modal: true
                model: ListModel {
                    ListElement {
                        text: "HIGH SPEED (162,5 mm/sec)"
                        
                    }
                    ListElement {
                        text: "MEDIUM 1 SPEED (130 mm/sec)"
                    }
                    ListElement {
                        text: "MEDIUM 2 SPEED (97,5 mm/sec)"
                    }
                    ListElement {
                        text: "LOW SPEED (56 mm/sec)"
                    }
                }
            }
        }
    
    D 1 Reply Last reply
    0
    • GrecKoG Offline
      GrecKoG Offline
      GrecKo
      Qt Champions 2018
      wrote on last edited by
      #3

      The better way would be to use the textRole, valueRole and currentValue properties of ComboBox

      model: ListModel {
          ListElement {
              text: "HIGH SPEED (162,5 mm/sec)"
              speed: 162.5 // or 4 or an enum or whatever
          }
          // ...
      }
      textRole: "text"
      valueRole: "speed"
      onActivated: systemController.speedPrinting = currentValue
      
      1 Reply Last reply
      2
      • D Damian7546

        Hi,
        How can I call this function systemController.speedPrinting === selectedItemFromComboBox depending on select item from below combobox ?

        ColumnLayout {
                id: stacViewCombobox1
                width: 500
                anchors {
                    left: parent.left
                    leftMargin: 30
                    top: textSettingPrinter.bottom
                    topMargin: 30
                }
                ComboBox {
                    id: mycombo
                    Layout.fillWidth: true
                    font.pointSize: 16
                     popup.modal: true
                    model: ListModel {
                        ListElement {
                            text: "HIGH SPEED (162,5 mm/sec)"
                            
                        }
                        ListElement {
                            text: "MEDIUM 1 SPEED (130 mm/sec)"
                        }
                        ListElement {
                            text: "MEDIUM 2 SPEED (97,5 mm/sec)"
                        }
                        ListElement {
                            text: "LOW SPEED (56 mm/sec)"
                        }
                    }
                }
            }
        
        D Offline
        D Offline
        Drooke
        wrote on last edited by Drooke
        #2

        @Damian7546
        provide a value for your List Elements
        Provide an id to your model (listModelId)
        Connect to onActivated(index) from combo box
        This should provide the index in the model you need to call your function
        setSpeed(listModelId.at(index).value)

        D 1 Reply Last reply
        0
        • GrecKoG Offline
          GrecKoG Offline
          GrecKo
          Qt Champions 2018
          wrote on last edited by
          #3

          The better way would be to use the textRole, valueRole and currentValue properties of ComboBox

          model: ListModel {
              ListElement {
                  text: "HIGH SPEED (162,5 mm/sec)"
                  speed: 162.5 // or 4 or an enum or whatever
              }
              // ...
          }
          textRole: "text"
          valueRole: "speed"
          onActivated: systemController.speedPrinting = currentValue
          
          1 Reply Last reply
          2
          • D Drooke

            @Damian7546
            provide a value for your List Elements
            Provide an id to your model (listModelId)
            Connect to onActivated(index) from combo box
            This should provide the index in the model you need to call your function
            setSpeed(listModelId.at(index).value)

            D Offline
            D Offline
            Damian7546
            wrote on last edited by
            #4

            @Drooke works !

            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