Results 1 to 12 of 12

Thread: setValidator

  1. #1
    Join Date
    Feb 2006
    Posts
    51
    Thanks
    7

    Default setValidator

    hello guys,

    i have a question about whether there is a way to use setValidator for the qtable. I have 3 cols and one of them is editable but i want to restrict the users to type for example integers between 2 and 16000. can someone tell me if it is possible??. I use qt3 and am a beginner on this area.

    thanx in advance.
    Love::Peace

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: setValidator

    You might try to reimplement this:
    QWidget * QTableItem::createEditor () const [virtual]
    This virtual function creates an editor which the user can interact with to edit the cell's contents. The default implementation creates a QLineEdit.
    If the function returns 0, the cell is read-only.
    The returned widget should preferably be invisible, ideally with QTable::viewport() as parent.
    If you reimplement this function you'll almost certainly need to reimplement setContentFromEditor(), and may need to reimplement sizeHint()
    or QTable::createEditor().

  3. #3
    Join Date
    Feb 2006
    Posts
    51
    Thanks
    7

    Default Re: setValidator

    Quote Originally Posted by jacek
    You might try to reimplement this:
    or QTable::createEditor().
    yes it works like this en thnx for the information.. i have now another problem with the validate values.. i want to type only the integers bigger than 2 and smaller than 16000. i have this line code:---

    Qt Code:
    1. QRegExp RegExp( "^[3-9]\\d{0,4}$" );
    To copy to clipboard, switch view to plain text mode 

    but this is ofcourse not good because i validate the values between 3 to 9 and with 4 zeros.. is there a way to just validate this 2> and <16000??

    thnx in advance..
    Love::Peace

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: setValidator

    Try:
    Qt Code:
    1. "^1[0-5]\\d{3}|[1-9]\\d\\d?|[2-9]$"
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Feb 2006
    Posts
    51
    Thanks
    7

    Default Re: setValidator

    Quote Originally Posted by jacek
    Try:
    Qt Code:
    1. "^1[0-5]\\d{3}|[1-9]\\d\\d?|[2-9]$"
    To copy to clipboard, switch view to plain text mode 
    no it does not work, i shouldnt type 1, 2 all integers bigger dan 2 and smaller than 16000

    its a bit tricky cuz if i dont want to type 1 then i am not able to type 11 and 16000..
    Love::Peace

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: setValidator

    Does this work?
    Qt Code:
    1. "^(?:1[0-5]\\d{3}|[1-9]\\d{1,3}|[3-9])$"
    To copy to clipboard, switch view to plain text mode 

  7. #7
    Join Date
    Feb 2006
    Posts
    51
    Thanks
    7

    Default Re: setValidator

    Quote Originally Posted by jacek
    Does this work?
    Qt Code:
    1. "^(?:1[0-5]\\d{3}|[1-9]\\d{1,3}|[3-9])$"
    To copy to clipboard, switch view to plain text mode 
    this works partially.. the integers < 16000 works fine but i am still able to type 1 and 2.. this part doent work >2(bigger than 2 means no 0, 1 and 2)
    Love::Peace

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: setValidator

    Quote Originally Posted by :db:sStrong
    but i am still able to type 1 and 2.. this part doent work >2(bigger than 2 means no 0, 1 and 2)
    How do you expect to type in 11111 if you can't type in 1?

  9. #9
    Join Date
    Feb 2006
    Posts
    51
    Thanks
    7

    Default Re: setValidator

    Quote Originally Posted by jacek
    How do you expect to type in 11111 if you can't type in 1?
    yep thats why it is abit dumb if am not able to type 1 then i cant type 11111 either but i have to find way to dont allow 1 an 2 but do allow i.e 11, 11111, 12, 12222...
    Love::Peace

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: setValidator

    Quote Originally Posted by :db:sStrong
    yep thats why it is abit dumb if am not able to type 1 then i cant type 11111 either but i have to find way to dont allow 1 an 2 but do allow i.e 11, 11111, 12, 12222...
    It should work --- according to kregexpeditor the above regexp doesn't match "0", "1" and "2".

    You could use QSpinBox instead of QLineEdit.

  11. #11
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: setValidator

    Couldn't you find a way to access the string, convert it to integer and check if it match your needs?
    I guess some signals or event allows you to do that...
    Current Qt projects : QCodeEdit, RotiDeCode

  12. #12
    Join Date
    Feb 2006
    Posts
    51
    Thanks
    7

    Default Re: setValidator

    Quote Originally Posted by fullmetalcoder
    Couldn't you find a way to access the string, convert it to integer and check if it match your needs?
    I guess some signals or event allows you to do that...
    No i couldnt find a way to do such but i dont think so i have to convert string to integers but i am going search in qt documentation ...

    thnxx
    Love::Peace

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.