AntiClipSettings/qml/IpTextField.qml

44 lines
1.2 KiB
QML
Raw Permalink Normal View History

2024-08-24 22:35:35 +08:00
import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts 1.15
2024-08-21 16:03:49 +08:00
Column {
id: root
property alias text: input.text
property bool valid: false
property bool canEmpty: false
2024-08-26 14:55:15 +08:00
property var regularExpression : /^(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])$/
2024-08-21 16:03:49 +08:00
TextField {
2024-08-27 11:14:36 +08:00
height: 44
2024-08-21 16:03:49 +08:00
width: 350
id: input
2024-08-26 16:46:41 +08:00
selectByMouse: true
2024-08-21 16:03:49 +08:00
onTextChanged: {
validate()
2024-08-21 16:03:49 +08:00
}
}
Text {
id: hint
color: "red"
font.pixelSize: 12
}
2024-08-22 10:48:28 +08:00
function reset() {
hint.text = ""
2024-08-21 16:03:49 +08:00
}
function validate() {
if (input.text.length <= 0) {
hint.text = root.canEmpty ? "" : "参数不能为空"
root.valid = root.canEmpty
return root.valid
}
2024-08-26 14:55:15 +08:00
root.valid = root.regularExpression.test(input.text)
if (!root.valid) {
hint.text = "参数配置无效"
} else {
hint.text = ""
}
return root.valid
}
2024-08-21 16:03:49 +08:00
}