PDA

View Full Version : Best widget for number input



bikonja
28th July 2015, 13:46
Hey guys, i'm making a simple currency exchange application and i need a widget for a number input from my future users.
I've been doing some reading and can't seem to find "the best solution" for getting the input.

I first thought of using a textEdit, and a QValidator to restrict the input for numbers only, but other(s) suggest that a QSpinBox would be a better option.
I would like to skip the part of coding where i have to check if the input is number etc, etc... and just bluntly ignore any other input if its not a number.
Basicly I want it to look and act like a basic windows calculator's input.

I dont want it to act like a QSpinBox because i dont need steps which the SpinBox offers;I know i can visually remove the arrows, but can i "remove" the mechanism completely?

Or to put it simple:

What widget is the best to use if i want to mirror a basic calculator input?

anda_skoa
28th July 2015, 14:57
QLineEdit with a QDoubleValidator or a QDoubleSpinBox

Cheers,
_

Nomad_Tech
6th August 2015, 13:24
Number input is 90% of what I do as I write calibration tools for scientific equipment and I have to agree with anda_skoa. Line Edits are the way to go. If you use a Double or Int Validator you wont have to write any code to check if the input is a number or has special characters etc as the validator won't allow the user to even type anything that isn't a number. I tend to use Line Edits with a lot of control over widget focus so that technical staff can enter a number and the cursor is already on the next edit that they need to type a value into. It's a very quick way of getting user input.

...That being said, if you really really want to use Spin Boxes, I'd perhaps re-implement KeyPressEvent in your main program, write a function to read numbers typed by the user and use that keyboard input to set the value of your spin boxes?