Qt工作笔记-QML中TextInput设置默认值,以及使用正则表达式只能输入整数
生活随笔
收集整理的這篇文章主要介紹了
Qt工作笔记-QML中TextInput设置默认值,以及使用正则表达式只能输入整数
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
程序運行截圖如下:
源碼如下:
import QtQuick 2.5 import QtQuick.Window 2.2Window {visible: truewidth: 640height: 480title: qsTr("Hello World")Rectangle{width:parent.widthheight:8+14color:"lightsteelblue"border.color: "gray"}TextInput{height:8anchors.fill: parentfont.pixelSize: 22focus:true} }如果要設置默認值:
就加一個text屬性,代碼如下:
TextInput{height:8text:"500"anchors.fill: parentfont.pixelSize: 22focus:true}運行截圖如下:
?
最簡單的正則表達式:
1.只能輸入2位整數:
TextInput{height:8text:"1"anchors.fill: parentfont.pixelSize: 22focus:truevalidator: RegExpValidator{regExp:/[0-9][0-9]/}}?
總結
以上是生活随笔為你收集整理的Qt工作笔记-QML中TextInput设置默认值,以及使用正则表达式只能输入整数的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Qt工作笔记-QLineEdit中使用s
- 下一篇: QML与C++混合编程详解