ComboBox 是一个组合的按钮和弹出列表。它提供了一种以最小的屏幕空间呈现选项列表给用户的方式。ComboBox 使用数据模型填充。数据模型通常是一个 JavaScript 数组、一个 ListModel 或一个整数,但也支持其他类型的数据模型。
下面是一个简单的使用方式。
import QtQuick
import QtQuick.ControlsWindow {width: 640height: 480visible: truetitle: qsTr("Hello World")QtObject {id: backendproperty real txtScaler : 100}ListModel {id: scaleModelListElement {scalePercent: "100%"scaleNumber: 100}ListElement {scalePercent: "90%"scaleNumber: 90}ListElement {scalePercent: "80%"scaleNumber: 80}ListElement {scalePercent: "70%"scaleNumber: 70}ListElement {scalePercent: "60%"scaleNumber: 60}ListElement {scalePercent: "50%"scaleNumber: 50}ListElement {scalePercent: "40%"scaleNumber: 40}ListElement {scalePercent: "30%"scaleNumber: 30}ListElement {scalePercent: "20%"scaleNumber: 20}ListElement {scalePercent: "10%"scaleNumber: 10}}ComboBox {anchors.centerIn: parenttextRole: "scalePercent"valueRole: "scaleNumber"model: scaleModelonActivated: backend.txtScaler = currentValueComponent.onCompleted: currentIndex = indexOfValue(backend.txtScaler)}
}