QML工作笔记-2种输入框的使用(TextField与TextInput)
生活随笔
收集整理的這篇文章主要介紹了
QML工作笔记-2种输入框的使用(TextField与TextInput)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
目錄
?
?
演示
代碼
?
演示
這里如下圖,上個的那個是TextField,下面的那個是TextInput加一個Rectangle
其中上面那個藍框包著的就是TextField,下面那個是TextInput
?
這里的最大區別就是如下,當數據很長的時候,是這樣的
從中可以看到,使用TextInput他的范圍可能會出Rectangle的范圍,但是這種的比較靈活,可以完成很多的功能!
?
或者限制TextInput的輸入。比如只能輸入15個字符,這樣也是可以繞過去的!
?
代碼
公共代碼:
main.qml
import QtQuick 2.9 import QtQuick.Window 2.2Window {visible: truewidth: 500height: 900title: qsTr("九州修仙大陸")Login{id: loginwidth: parent.widthheight: parent.height}}TextField
的代碼:
TextField{height: userNameText.heightwidth: loginBtn.width * 1.5font.pointSize: passwdNormalSize - 5focus: true }TextInput加Rectangle的輸入框:
Rectangle {width: loginBtn.width * 1.5height: passwdInput.contentHeight + 5color: "white"border.color: "grey"anchors.horizontalCenter: passwdText.CenterTextInput {id: passwdInputanchors.fill: parentanchors.margins: 2font.pointSize: passwdNormalSizefocus: trueanchors.horizontalCenter: passwdText.Center} }?
總結
以上是生活随笔為你收集整理的QML工作笔记-2种输入框的使用(TextField与TextInput)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: C++笔记-lambda表达式需要注意的
- 下一篇: Redis工作笔记-spring-dat