Locator / longitude Qt4 widget?

What is the best starting point for a Qt4 widget to enter Latitude / Longitude in DD: MM: SS format (degrees, minutes, seconds)? Customize QLineEdit? A series of spin boxes?

+6
qt qt4 pyqt pyqt4
source share
2 answers

There are several options:

QLineEdit with Validator is not enough for us, we were unable to achieve convenient editing and correct presentation (with symbols "," and "degrees" in place and the ability to prohibit incorrect values ​​and still allow semi-correct states, and the target behavior is not to flag errors and force the user to correct them, and so that the user can enter only valid values).

Three spins are edited in a line with the corresponding characters between them, grouped as one widget and some code to move keyboard input from one next to the right, etc. In some cases, it looks good enough, and you can find an implementation option in the famous Marble project.

However, my boss said that this approach is almost as ugly as the first, so here is another approach: a subclass of QAbstractSpinBox, as Trolltech did in its QDateTimeEditor. In fact, the behavior of such a widget is almost similar to the one implemented in QDateTimeEditor. I myself have not done this yet, setting priorities for the tasks, but I will have to do it.

+6
source share

I would use a QValidator , attaching it to a QLineEdit with QLineEdit::setValidator() .

You will need a subclass so that you can implement the validate() function, and possibly the fixup() function for your specific case, since the two validators included in Qt cover only integers and paired numbers.

It is a little friendlier, in my opinion, to provide a single input block for this, rather than three separate rectangles (which may look cluttered and not so good for input).

[Edit: Another alternative is to set the confirmation input mask on your QLineEdit using QLineEdit::setInputMask() . You may need to edit the line with characters already set and, for example, placeholders for other characters, and this approach will give you something similar for this. The QtDemo application has an example of this, which you can check by choosing Widgets-> Line Edits (Widgets are on the second page).]

+2
source share

All Articles