QML的复选框是CheckBox,使用代码如下:
import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Controls 2.5
import QtQuick.Layouts 1.12
Window {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
ColumnLayout {
x:20
y:20
CheckBox {
id:ch1
checked: true
text: qsTr("First")
}
CheckBox {
id:ch2
text: qsTr("Second")
}
CheckBox {
id:ch3
checked: true
text: qsTr("Third")
}
Button{
text: "获取CheckBox状态"
onClicked: {
console.log(ch1.checked)
console.log(ch2.checked)
console.log(ch3.checked)
}
}
}
}
运行界面