Results 1 to 3 of 3

Thread: QLineEdit for editing hexadecimal and decimal numbers

  1. #1
    Join Date
    Jan 2008
    Location
    Germany
    Posts
    80
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default QLineEdit for editing hexadecimal and decimal numbers

    I would like to use a QLineEdit control to edit or decimal (0..255) or hexadecimal (0x00 .. 0xFF) numbers. The user should be able to enter the number in one or the other format, and the decimal number has to be limited to 255.

    Can this all be done by using only a QRegExp for the validator ?
    Does anyone has an idea how the validator would then look like ?

  2. #2
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QLineEdit for editing hexadecimal and decimal numbers

    something like
    Qt Code:
    1. QRegExp("[0-9A-F]{,2}|\\d{,3}")
    To copy to clipboard, switch view to plain text mode 
    should work

  3. #3
    Join Date
    Apr 2012
    Posts
    14
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QLineEdit for editing hexadecimal and decimal numbers

    This will NOT work correctly!

    "\\d{,3}" accepts digits in the range 0-999.

    Try this:
    Qt Code:
    1. QRegExp re("^\\b(0x([0-9A-F]{1,2}))|(([0-2])([0-5])?([0-5])?)\\b$");
    To copy to clipboard, switch view to plain text mode 

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.