Results 1 to 4 of 4

Thread: QLineEdit inputMask and validator

  1. #1
    Join Date
    Jul 2012
    Posts
    20
    Thanks
    8
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4

    Default QLineEdit inputMask and validator

    I have a Widget with a LineEdit in it. Input of LineEdit must be restrict special symbol. I used inputMask to do this work.
    But, now I have trouble.
    Qt Code:
    1. ui->lineEdit->setInputMask("N");
    To copy to clipboard, switch view to plain text mode 
    The code above allow me to input only 1 character.
    Qt Code:
    1. ui->lineEdit->setInputMask("NNN");
    To copy to clipboard, switch view to plain text mode 
    The code above allow me to input only 3 character.

    Assumming, the lineEdit allow user input maxlength = 1000, so I have do this:
    Qt Code:
    1. ui->lineEdit->setInputMask("NNNNNNNNNNNNNNNNNN.......N (1000 times)");
    To copy to clipboard, switch view to plain text mode 
    Very stupid. Is there another way to avoid that. How can I solve ????)

  2. The following user says thank you to vhptt for this useful post:

    Hossein (1st September 2012)

  3. #2
    Join Date
    May 2012
    Location
    Bangalore, India
    Posts
    271
    Thanks
    29
    Thanked 50 Times in 47 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Cool Re: QLineEdit inputMask and validator

    yes,,,, put all that in for loop like this:-

    Qt Code:
    1. QString str;
    2. for(int i=0;i<1000;i++){
    3. str.append("N");
    4. }
    5. ui->lineEdit->setInputMask(str);
    To copy to clipboard, switch view to plain text mode 

    Got it or still confused.
    Heavy Metal Rules. For those about to rock, we salute you.
    HIT THANKS IF I HELPED.

  4. The following 2 users say thank you to sonulohani for this useful post:

    Hossein (1st September 2012), vhptt (3rd August 2012)

  5. #3
    Join Date
    Mar 2006
    Posts
    74
    Thanks
    1
    Qt products
    Qt3
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QLineEdit inputMask and validator

    Even simpler:

    QString mask(1000, QChar(' '));

  6. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QLineEdit inputMask and validator

    1000 characters with no spaces, line breaks, or punctuation? Really?

Similar Threads

  1. QLineEdit validator
    By pobere in forum Newbie
    Replies: 2
    Last Post: 5th November 2011, 10:16
  2. set cursor position in qlineedit with an inputmask
    By guitar1 in forum Qt Programming
    Replies: 2
    Last Post: 11th March 2011, 17:13
  3. Replies: 2
    Last Post: 25th November 2010, 06:00
  4. Focus problem with QLineEdit and InputMask
    By ttvo in forum Qt Programming
    Replies: 2
    Last Post: 26th May 2009, 13:57
  5. Replies: 10
    Last Post: 12th February 2009, 07:23

Tags for this Thread

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.