Results 1 to 12 of 12

Thread: how to make input mask and validator work together?

  1. #1
    Join Date
    Mar 2009
    Posts
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default how to make input mask and validator work together?

    After I set input mask "000 000 000" to my QLineEdit and then set QRegExpValidator "(\\d{3}) (\\d{3}) (\\d{3})" to it, I can't input number in the QLineEdit. But each of them works OK separately.

    How can I write the QRegExpValidator to match the input mask and make them work together?

  2. #2
    Join Date
    May 2008
    Location
    Kyiv, Ukraine
    Posts
    418
    Thanks
    1
    Thanked 29 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: how to make input mask and validator work together?

    If each of them works fine separately, then would you need them to work together? Is either one of them not enough for your case?
    I'm a rebel in the S.D.G.

  3. #3
    Join Date
    Mar 2009
    Posts
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to make input mask and validator work together?

    yes, I original set the input mask. but some one else may use this widget I provided and set validator for it.

  4. #4
    Join Date
    May 2008
    Location
    Kyiv, Ukraine
    Posts
    418
    Thanks
    1
    Thanked 29 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: how to make input mask and validator work together?

    So, you are creating a widget that may be used for others.

    Well, then one of possible solutions is to provide methods, something like
    Qt Code:
    1. setValidator(Validator ...);
    2. setInputMask(InputMask ...);
    To copy to clipboard, switch view to plain text mode 

    which will set the desired mechanism and clear the second. I mean you want to use a validator, you call setValidator(your_validator) which sets it and clears the input mask (if it is set).
    I'm a rebel in the S.D.G.

  5. #5
    Join Date
    Mar 2009
    Posts
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to make input mask and validator work together?

    when set validator to line edit, you can remove the already input mask. but my question is how to make them work together? Use the input mask and how to write a good validator to math the input mask?

  6. #6
    Join Date
    May 2008
    Location
    Kyiv, Ukraine
    Posts
    418
    Thanks
    1
    Thanked 29 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: how to make input mask and validator work together?

    Well, then i don't understand what you are trying to say by your

    but some one else may use this widget I provided and set validator for it.
    I'm a rebel in the S.D.G.

  7. #7
    Join Date
    Mar 2009
    Posts
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to make input mask and validator work together?

    first I set default input mask for line edit. but some one else wants to set a validator for it.

  8. #8
    Join Date
    May 2008
    Location
    Kyiv, Ukraine
    Posts
    418
    Thanks
    1
    Thanked 29 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: how to make input mask and validator work together?

    counter-question:

    Do these input mask and validator do the SAME kind of validation/verification?

    If yes, i don't see any problem with clearing the input mask when someone sets the validator.
    I'm a rebel in the S.D.G.

  9. #9
    Join Date
    May 2008
    Location
    Kyiv, Ukraine
    Posts
    418
    Thanks
    1
    Thanked 29 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: how to make input mask and validator work together?

    Tell us a little bit about your widget, so we can get the main idea of what you are doing.
    I'm a rebel in the S.D.G.

  10. #10
    Join Date
    Mar 2009
    Posts
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to make input mask and validator work together?

    my widget is a line edit. for example I set it with input mask "000.000.000.000" (this is a IP address inp ut mask). Then some one else wants to set a validator to the line edit and the validator could forbide user input numbers which are larget than 255. How can I write the QRegExpValidator rules under the exist input mask?

  11. #11
    Join Date
    May 2008
    Location
    Kyiv, Ukraine
    Posts
    418
    Thanks
    1
    Thanked 29 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: how to make input mask and validator work together?

    Well, tell me, what is the purpose of this input mask when it doesn't provide the complete validation of IP addresses?
    I'm a rebel in the S.D.G.

  12. #12
    Join Date
    Mar 2009
    Posts
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to make input mask and validator work together?

    just notice user this is a IP address and user no need to input dot in line edit.

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.