PDA

View Full Version : QLineEdit for editing hexadecimal and decimal numbers



schall_l
4th March 2009, 09:05
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 ?

caduel
4th March 2009, 09:42
something like

QRegExp("[0-9A-F]{,2}|\\d{,3}")
should work

AlekseyOk
28th April 2012, 12:38
This will NOT work correctly!

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

Try this:

QRegExp re("^\\b(0x([0-9A-F]{1,2}))|(([0-2])([0-5])?([0-5])?)\\b$");