Solved QML combo box
-
Hello,
I have a list of elements in combo box. I want the combo box to do some action whenever I select anyone of the listed elements accordingly. -
Something like this?
ComboBox { model: ["One", "Two", "Three", "Four"] onActivated: console.log("I clicked item with index " + index + " which has label " + model[index]) }
-
@stcorp
Yes, Similar to the code which you provided. The checkbox should open another page when selected anyone in the list. When i use the code it throws an error as, "CANNOT RETRIEVE DEBUGGING OUTPUT" . -
It depends on how different you want each page for each user to be, but here is an example of how you could do it using a stackview.
main.qmlimport QtQuick 2.7 import QtQuick.Controls 2.0 ApplicationWindow { visible: true width: 500 height: 500 StackView { id: stackview initialItem: Pane { ComboBox { model: ["Anne", "Bob", "Charlie", "Dianne"] onActivated: stackview.push("qrc:/window.qml", {"name": model[index]}) } } } }
window.qml
import QtQuick 2.7 import QtQuick.Controls 2.0 Pane { property string name Column { Button { text: "Close" onClicked: stackview.pop() } Label { text: "This is an opened window for " + name } } }
Basically you have the homepage (initialItem) of the stackview, which displays the combobox. Then, whenever one of the names in the combobox is selected, it opens a new page from window.qml, with the property "name" being set to the selected name of the combobox.
-
Tanq Bro it worked perfect