Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. TextField still allows user input "0" with validator: IntValidator {bottom: 1; top: 100;}
Forum Update on Monday, May 27th 2025

TextField still allows user input "0" with validator: IntValidator {bottom: 1; top: 100;}

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
4 Posts 3 Posters 846 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    llllyxzy
    wrote on last edited by
    #1

    It will not pass this value to backend.
    How to forbid input "0" with a popup hint string?
    Thanks~

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      Have tried with accepted() signal ? This will emit only if the input is valid. You can show pop-up inside the accepted signal handler.

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      0
      • L Offline
        L Offline
        llllyxzy
        wrote on last edited by
        #3

        Thank you!
        When input is invalid, it keeps silent.
        So I finally do a trick by forcing no "0" from the begin (The input needs to be integers start from 1).
        onTextChanged: {
        if(text.substring(0, 1) == "0")
        text = "1"
        }

        1 Reply Last reply
        0
        • ODБOïO Offline
          ODБOïO Offline
          ODБOï
          wrote on last edited by ODБOï
          #4

          hi,

          TextField{
          validator: RegExpValidator { regExp: /^[1-9][0-9]*$/ }
          }

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved