![](/img/trans.png)
[英]From a numerical spinbox how to prevent the user from typing no numbers in QML
[英]How to prevent typing whitespace in TextEdit QML?
如何防止在 TextEdit 中輸入空格? QML
TextEdit {
width: 240
text: "123"
font.pointSize: 20
color: "blue"
}
如果您可以將文本輸入項從 TextEdit 更改為 TextInput 可以使用驗證器和正則表達式
來自文檔:
RegExpValidator 類型提供了一個驗證器,它將與指定的正則表達式匹配的任何字符串都視為有效。
以另一種方式可以獲得 onTextChanged 信號並刪除空格:像這樣:
TextEdit {
width: 240
text: "123"
font.pointSize: 20
color: "blue"
onTextChanged:text = text.replace(/\s+/g,'')
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.