Results 1 to 3 of 3

Thread: QLineEdit validator

  1. #1
    Join Date
    Nov 2011
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default QLineEdit validator

    Hi,

    in a constructor of a class that inherits QLineEdit I have the following:

    Qt Code:
    1. setInputMask("99:99");
    2. QRegExp regexp("^([0-1][0-9]|[2][0-3]):([0-5][0-9])$");
    3. QRegExpValidator *validator = new QRegExpValidator(regexp, this);
    4. setValidator(validator);
    To copy to clipboard, switch view to plain text mode 

    This helps me to display and edit the time.

    The validator works fine and also the input mask.The only problem is that:
    the cursor can be moved at the position 5, and here is no char to change!
    But we have in the mask only 5 chars, and the maximum position could be 4!

    How can I get rid of such an annoying thing.


    thanks.
    Last edited by pobere; 5th November 2011 at 09:51.

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QLineEdit validator

    Maybe QLineEdit::setMaxLength() could help you.

  3. #3
    Join Date
    Nov 2011
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QLineEdit validator

    Nope, it doesn't.
    If the line edit has an input mask, the mask defines the maximum string length.
    The max length should be already set to 5 (in my case) by the mask...

    I think, the validator should also validate the cursor position ... but it doesn't only for the last position (which is not valid).

Similar Threads

  1. Use QLineEdit with mask AND validator for money OUTPUT
    By luboni in forum Qt Programming
    Replies: 4
    Last Post: 16th August 2011, 17:29
  2. How to create a validator
    By Cucus in forum Newbie
    Replies: 1
    Last Post: 4th August 2011, 07:47
  3. Validator
    By tinysoft in forum Newbie
    Replies: 5
    Last Post: 13th April 2011, 16:00
  4. Validator for QDoubleSpinBox
    By ehamberg in forum Qt Programming
    Replies: 3
    Last Post: 15th March 2008, 11:37
  5. QRegExp validator
    By mattia in forum Newbie
    Replies: 2
    Last Post: 28th November 2007, 08:15

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.