Results 1 to 4 of 4

Thread: QLineEdit

  1. #1
    Join Date
    May 2009
    Posts
    94
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Windows

    Post QLineEdit

    I created a QLineEdit.I set inputmask as - 9.
    If user is typing any other character other than digit QLineEdit text should not change. How can i do this.

  2. #2
    Join Date
    May 2009
    Posts
    129

    Default Re: QLineEdit

    use validator

    Thanks

    Yuvaraj R

  3. #3
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QLineEdit

    Try:
    Qt Code:
    1. lineEdit->setInputMask("9999");//Will let you enter 4 digits
    To copy to clipboard, switch view to plain text mode 
    Last edited by yogeshgokul; 11th August 2009 at 06:40.

  4. #4
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QLineEdit

    QValidator is a better way than input mask. There are currently 3 validators prepared in Qt: QDoubleValidator, QIntValidator, QRegExpValidator.

    If you want to validate as the input string is an int you can do it like this (from Qt Assistant):
    Qt Code:
    1. QValidator *validator = new QIntValidator(100, 999, this);
    2. QLineEdit *edit = new QLineEdit(this);
    3.  
    4. // the edit lineedit will only accept integers between 100 and 999
    5. edit->setValidator(validator);
    To copy to clipboard, switch view to plain text mode 
    If you want some reg exp validating than:
    Qt Code:
    1. QRegExp rx("[1-9]\\d{0,3}");
    2. QValidator *validator = new QRegExpValidator(rx, this);
    3. QLineEdit *edit = new QLineEdit(this);
    4. edit->setValidator(validator);
    To copy to clipboard, switch view to plain text mode 
    will allow you to input numbers between 1 and 9999;
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

Similar Threads

  1. Replies: 10
    Last Post: 12th February 2009, 07:23
  2. QLineEdit actions in Delegate
    By mclark in forum Qt Programming
    Replies: 1
    Last Post: 15th January 2009, 21:34
  3. QLineEdit
    By rick_st3 in forum Newbie
    Replies: 1
    Last Post: 14th June 2008, 09:05
  4. Pointer Question related to QLineEdit
    By ChrisReath in forum Qt Programming
    Replies: 1
    Last Post: 23rd May 2008, 15:13
  5. QValidator, regular expressions and QLineEdit
    By hvengel in forum Qt Programming
    Replies: 1
    Last Post: 8th August 2007, 01:25

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.