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. TextInput how to block entering new data if current value is out of range?

TextInput how to block entering new data if current value is out of range?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
2 Posts 1 Posters 360 Views 1 Watching
  • 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.
  • GoodGuyG Offline
    GoodGuyG Offline
    GoodGuy
    wrote on last edited by aha_1980
    #1

    I'm looking for way to block entering new data if current value if out of range. I was check the TextInput validator property with a range but setting it just block possibility to press enter, not input new.

    I was tried to use onTextEdited and remove last character but new number is added after this, so in the end always remove one before last digit. Any idea?

    						onTextEdited:
    						{
    							if ((text < analogValid.bottom) ||  (text > analogValid.top))
    							{
    								console.log("onTextEdited: " + text);
    								textInputComp.remove(selectionEnd-1,  selectionEnd);
    							}
    						}
    
    1 Reply Last reply
    0
    • GoodGuyG Offline
      GoodGuyG Offline
      GoodGuy
      wrote on last edited by
      #2

      IIm not sure if is it a proper way but i solved my problem. I just save the old value of text property in by buffer onTextEdited .
      The onTextEdited will be called before text will be changed. After that text will be changed and automaticly callingonTextChanged where text value will be checked.

      onTextEdited:
      {
      	if ((validator === analogValid) && (text >= analogValid.bottom) && (text <= analogValid.top))
      		oldTextVal = text;
      }
      
      onTextChanged:
      {
      	if ((validator === analogValid)  && ((text < analogValid.bottom) || (text > analogValid.top)))
      		text = oldTextVal;
      }
      
      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