qml之ip地址框的实现

这是一个使用QML实现的矩形组件,包含四个输入框用于输入IPv4地址,每个输入框都有长度限制和正则表达式验证,确保输入合法。当输入达到特定条件时,焦点会自动转移到下一个输入框。此外,组件还支持输入法面板的显示和更新。
摘要由CSDN通过智能技术生成

 Rectangle{
                            id:rectange1
                             x:101
                             y:52
                             width:280
                             height: 40
                             border.color: "#000000"

                             TextField {
                                  id: textinput1
                                  x: 0
                                  y: 0
                                  width: 280
                                  height: 40
                                  font.pointSize: 10
                                  text: setform.ip
                                  onTextChanged: {
                                      if(text.length === 3 || text > 255)
                                         // nextItemInFocusChain().forceActiveFocus()
                                          textinput2.focus = true
                                  }

                                  validator: RegExpValidator{regExp:/(?=(\b|\D))(((\d{1,2})|(1\d{1,2})|(2[0-4]\d)|(25[0-5]))\.){3}((\d{1,2})|(1\d{1,2})|(2[0-4]\d)|(25[0-5]))(?=(\b|\D))/}

                                  onActiveFocusChanged: {
                                      if(activeFocus) {
                                                  Qt.inputMethod.update(Qt.ImQueryInput)
                                              }
                                  }
                                  onPressed: {
                                      inputPanel1.visible = true
                                  }
                             }

                                TextInput {
                                       id: textinput2
                                       x: 70
                                       y: 0
                                       width: 70
                                       height: 40
                                      // text: setform.i2
                                       horizontalAlignment: Text.AlignHCenter
                                       font.pointSize: 10
                                       onTextChanged: {
                                           if(text.length === 3 || text > 255)
                                              // nextItemInFocusChain().forceActiveFocus()
                                               textinput3.focus = true
                                       }
                                  //     KeyNavigation.tab: textinput3
                                       validator: RegExpValidator{regExp:/(?=(\b|\D))(((\d{1,2})|(1\d{1,2})|(2[0-4]\d)|(25[0-5]))\.){3}((\d{1,2})|(1\d{1,2})|(2[0-4]\d)|(25[0-5]))(?=(\b|\D))/}
                                   }

                                   TextInput {
                                       id: textinput3
                                       x: 140
                                       y: 0
                                       width: 70
                                       height: 40
                                       horizontalAlignment: Text.AlignHCenter
                                       font.pointSize: 10
                                       onTextChanged: {
                                           if(text.length === 3  || text > 255)
                                              // nextItemInFocusChain().forceActiveFocus()
                                               textinput4.focus = true
                                       }

                                   //    KeyNavigation.tab: textinput4
                                       validator: RegExpValidator{regExp:/(?=(\b|\D))(((\d{1,2})|(1\d{1,2})|(2[0-4]\d)|(25[0-5]))\.){3}((\d{1,2})|(1\d{1,2})|(2[0-4]\d)|(25[0-5]))(?=(\b|\D))/}
                                   }
                                   TextInput {
                                       id: textinput4
                                       x: 210
                                       y: 0
                                       width: 70
                                       height: 40
                                       horizontalAlignment: Text.AlignHCenter
                                       font.pointSize: 10
                                       onTextChanged: {
                                           if(text.length === 3  || text > 255)
                                               nextItemInFocusChain().forceActiveFocus()
                                              // textinput5.focus = true
                                       }
                                       validator: RegExpValidator{regExp:/(?=(\b|\D))(((\d{1,2})|(1\d{1,2})|(2[0-4]\d)|(25[0-5]))\.){3}((\d{1,2})|(1\d{1,2})|(2[0-4]\d)|(25[0-5]))(?=(\b|\D))/}
                                   }

                                   Text {
                                       id: text11
                                       x: 68
                                       y: 0
                                       width: 4
                                       height: 40
                                       text: qsTr(".")
                                       font.pointSize: 8
                                   }
                                   Text {
                                       id: text12
                                       x: 138
                                       y: 0
                                       width:4
                                       height: 40
                                       text: qsTr(".")
                                       font.pointSize: 8
                                   }
                                   Text {
                                       id: text13
                                       x: 208
                                       y: 0
                                       width: 4
                                       height: 40
                                       text: qsTr(".")
                                       font.pointSize: 8
                                   }

                }

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值