I am currently creating an application with Qt and have found a class named QIntValidator whichs allows to check whether the contents of a QLineEdit is actually an integer or not. This class allows to check on the fly whether the entered contents are correct and to signal the user if they entered a string which does not represent an integer.

While the contents validation is interesting by itself, from a user experience point of view, why would I specifically want to use a one-line text editor to enter integral values when I could simply use an integer spinbox that, when correctly configured, prevents the user from even entering characters that would make the represented integer ill-formed? I have found many forms that used one-line text editors to enter integer values, but I still can't understand why they would use them instead of spinboxes.

Moreover, if one doesn't like the spinbox buttons, many GUI systems even allow to hide them.

Spin box example

  • 2
    One reason is Accessibility - How do you interact with a spinner if you're just using a keyboard? Plus speed. It's a lot easier and faster to type 1727 than it is to interact with 4 different spinner items and set each of them to the number you want.
    – JonW
    Feb 20 '15 at 10:44
  • 4
    @JonW: Interacting with a spinbox with just a keyboard is easy. It accepts keyboard input like any other widget, and also allows to increase and decrease the value using the keyboard, both in small and in big steps. Note that QSpinBox is not the same as an iOS spinner control.
    – André
    Feb 20 '15 at 11:13
  • 1
    if you can type in a spin box then it seems like it's the best solution for your app. If it's a Qt app then I assume it will be exclusively used on a desktop platform so you don't have concern with mobile input issues and thumb-accuracy.
    – sova
    Feb 20 '15 at 16:09

The answers here seem to assume (incorrectly) that a SpinBox is constrained to only adjusting the number using the provided up-down buttons. I've never seen this be true.

If anything, a SpinBox is a desktop convention provides the following:

  • A visual cue that the TextBox is expecting a number.
  • Allows the textbox to be incremented and decremented using the keyboard (useful for a UI that updates instantly in response to value changes).

To be honest, the arrows being clickable by a mouse is an afterthought, since it's realistically never used in this manner. For example, in HTML5, a <input type="number" /> field is typically rendered as a SpinBox on the desktop, but is a TextBox with a number keyboard on mobile.

As to why use a TextBox with a validator over a SpinBox, mrBussy had the correct answer in a comment: Consistency. You may have a TextBox that can change data types, and only changing the validator means the UI never changes, only the validated input.

  • to be more accurate, there are spinners for touch interfaces (they tend to take the bottom half of the screen when the field is tapped).
    – Dvir Adler
    Mar 10 '15 at 15:31

I really do not like spinners. For several reasons.

  • The up and down buttons are typically tiny and adjacent to each other, which creates unnecessary user frustration with getting to the right button. This is especially true when users are on trackpads or ipad, because of the combination of fuzzy finger focus and "click-shift" with certain trackpads.

  • For many (but not all) use cases they are an example of unnecessarily constrained UX behavior. If the default value is zero and I need to enter '42', I have to click 42 times. If I have the option to enter the number using the keypad, then why not just give me the option to begin with and remove the added cognitive complexity of the up/down buttons?

  • Often they are used in situations where the designer wants to constrain values to some enumerated list (e.g. camera f-stops: 2.8, 3.5, 4, 5.6, etc). In this case, the user still has to click too many times to get to the right value...it's easier just to provide one-click dropdown so the user can easily see the choices and select the right now.

I could go on, but I think the point is made. There are a few instances where I think they might be appropriate. One is "fine-tuning" behavior where the range of likely inputs is clustered narrowly around some median. For example, fine-tuning focus for a microsocope, where zero is the autofocus and you may want to adjust one or two steps out. Here, the feedback of the "one click" adjustment is helpful in terms of deliberately constraining and pacing user behavior in a positive way.

  • Forget entering something easy like "42". Try using a spinner to enter last year's before-tax income into an accounting program to see why you want free input of numbers.
    – Mark
    Feb 22 '15 at 6:40
  • And a followup to my comment: I just encountered someone who thought using a spinner to enter a credit-card number was a good idea. My mind has been boggled.
    – Mark
    Jul 26 '16 at 6:52

A good reason for using a QSpinBox is to make it obvious what input is expected. If you just put a QLineEdit there with an QIntValidator installed on it, it will look like you can enter anything there, but in practice you won't be able to. That may be confusing for people. Conversely, it will be harder for users to make a slight change to a value than it would be if you were using a QSpinBox instead. That widget communicates that it takes numbers, but also allows direct entry and copy/paste like a QLineEdit does.

Note that in general, I don't like the design of spin boxes. Their up/down buttons usually are way too small targets.

However, note that validators can be used for other purposes as well.

  • Well yeah, but that doesn't answer my question which is: why would people use a QLineEdit and a QIntValidator (or equivalents) when they could usea QSpinBox? I am also aware that other validators for other purposes make sense, but why would people use an integer validator when they can have spinboxes?
    – Morwenn
    Feb 20 '15 at 12:31
  • André. I would think that people use it for consistancy. If you only have textboxes in your design introducing a new element can be confusing for users. Also using a spinner would restrict you to using into values only. Feb 20 '15 at 12:47

It occured to me today that one-line text editors are sometimes embedded into other widgets such as combo boxes where an IntValidator totally makes sense: there is no widget I know of that has both the properties of a combo box and of a spin box. However, a combo box may have a text field built on the top of a one-line text editor. Therefore, if one wants to choose an integer in a list (a list of ids for example) or to enter a new one that does not exist in the list, using a combo box with an integer validator would probably be the optimal solution.


If you're entering a potentially large numbers, an input with a number pad would be far more efficient than a spinbox.

Suppose you need to enter a 5-6 digit ID number. (e.g. driver's license, social insurance number, zip code etc). Would you want to use a spinbox for that?

I suppose you can break it down to 1 spinner per digit, but a number pad on a device would be far easier to deal with. One tap per number as oppose to manipulating the spinner to get to the number you need.

enter image description here

  • I think you're right, but your answer doesn't really say why a text input with a number pad would be easier. Feb 24 '15 at 9:28
  • @vincebowdren I thought it was clear that single tap to select will always be faster mechanically than rotating a spinner to arrive at the number you need. But I've modified the answer to clarify.
    – nightning
    Feb 24 '15 at 17:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.