Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Latitude/Longitude Qt4 widget?

Tags:

qt

qt4

pyqt

pyqt4

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

like image 789
Dave Avatar asked Mar 24 '10 20:03

Dave


2 Answers

There are some variants:

QLineEdit with Validator - wasn't good enough for us, we couldn't achieve usable editing and proper view (with ', '' and degree symbols in place and ability to forbid incorrect values and still allow semi-correct states, and the target behaviour is not to mark errors and force user to fix them, but to allow user to enter only valid values).

Three spin edits in a line with the proper symbols between them grouped as a single widget and some code to move keyboard input from one no next when needed etc. Looks good enough in some cases, and you can find the variant of realization in the famous Marble project.

Still, my boss said that this approach is almost as ugly as first, so here is another approach: subclass QAbstractSpinBox, as Trolltech did in their QDateTimeEditor. In fact, behaviour of such a widget is near similar to one, implemented in QDateTimeEditor. I, myself didn't do it yet, cause of task priorities, but will have to do.

like image 133
Maxim Popravko Avatar answered Sep 27 '22 18:09

Maxim Popravko


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

You'll need to subclass so you can implement the validate() function and possibly the fixup() function for your particular case, since the two validators included with Qt only cover integers and doubles.

It's a bit friendlier, in my opinion, to provide a single input box for this rather than three separate spin boxes (which could look cluttered and isn't as nice to type in).

[Edit: One other alternative is to set a "validation input mask" on your QLineEdit using QLineEdit::setInputMask(). You might want a line edit with symbols already in place and placeholders for other characters, for example, and this approach will give you something similar to that. The QtDemo app has an example of this which you can check out by choosing Widgets->Line Edits (Widgets is on the second page).]

like image 29
richardwb Avatar answered Sep 27 '22 20:09

richardwb