Results 1 to 2 of 2

Thread: Negative numbers on QLineEdit

  1. #1
    Join Date
    Mar 2011
    Posts
    34
    Qt products
    Qt4
    Platforms
    Windows

    Default Negative numbers on QLineEdit

    Hi,

    I'm trying to make an inputMask on my QLineEdit to ONLY accept negative and positive numbers with 2 decimals.

    Is it possible to do it or I need a QDoubleValidator?

    Thanks

  2. #2
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Negative numbers on QLineEdit

    You have to use QDoubleValidator or QRegExpValidator
    For example this QRegExp works for you
    Qt Code:
    1. QRegExp("[+-]?[1-9]\\d+\\.\\d{2}")
    To copy to clipboard, switch view to plain text mode 
    A camel can go 14 days without drink,
    I can't!!!

Similar Threads

  1. QLineEdit for editing hexadecimal and decimal numbers
    By schall_l in forum Qt Programming
    Replies: 2
    Last Post: 28th April 2012, 11:38
  2. Converting to negative int - bug
    By ShamusVW in forum Qt Programming
    Replies: 19
    Last Post: 22nd September 2010, 12:09
  3. How to use QLCDnumber to display negative numbers?
    By grissiom in forum Qt Programming
    Replies: 1
    Last Post: 19th March 2010, 06:23
  4. How to zoom in negative X and Y axis ?
    By biplab777 in forum Qwt
    Replies: 0
    Last Post: 9th June 2009, 10:55
  5. negative images
    By tommy in forum Qt Programming
    Replies: 3
    Last Post: 22nd January 2008, 10:41

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.