ComboBox list pass to Qt
-
Hi,
How can I call this functionsystemController.speedPrinting === selectedItemFromComboBoxdepending 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)" } } } } -
The better way would be to use the
textRole,valueRoleandcurrentValueproperties ofComboBoxmodel: 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 -
Hi,
How can I call this functionsystemController.speedPrinting === selectedItemFromComboBoxdepending 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)" } } } }@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) -
The better way would be to use the
textRole,valueRoleandcurrentValueproperties ofComboBoxmodel: 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 -
@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)@Drooke works !