Results 1 to 3 of 3

Thread: Best widget for number input

  1. #1
    Join Date
    Feb 2015
    Posts
    21
    Thanks
    2

    Default Best widget for number input

    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?

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Best widget for number input

    QLineEdit with a QDoubleValidator or a QDoubleSpinBox

    Cheers,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    Nomad_Tech (6th August 2015)

  4. #3
    Join Date
    Sep 2014
    Location
    Sydney, Australia
    Posts
    16
    Thanks
    2
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Best widget for number input

    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?
    "When the only tool you have is a hammer, every problem resembles a nail"

Similar Threads

  1. Know Number of Property Exposed by the Widget
    By Ashutosh2k1 in forum Qt Programming
    Replies: 4
    Last Post: 29th June 2011, 12:12
  2. [problem] No mouse input to child widget
    By Demandred in forum Newbie
    Replies: 3
    Last Post: 13th April 2010, 13:44
  3. Ip address input widget
    By jjbabu in forum Qt Tools
    Replies: 1
    Last Post: 28th September 2008, 20:36
  4. Displaying Page Number on a widget
    By LiCodeX in forum Newbie
    Replies: 1
    Last Post: 23rd August 2007, 08:34
  5. regarding input widget
    By jagadish in forum Qt Tools
    Replies: 1
    Last Post: 28th June 2007, 12:07

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
  •  
Qt is a trademark of The Qt Company.