Latitude/Longitude Qt4 widget? - qt

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?

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.

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).]

Related

Vaadin numeric field?

Is there a DoubleField or LongField Vaadin 7? I see a TextField and PasswordField, so it sort of shocked me when I did not see fields for numeric types. This seems so standard, especially since GWT has such fields under the hood, that I feel like I am missing something.
Also, there are some numeric field add-ons, but most of them say they don't support Vaadin 7, which leads me to believe there is some standard way to do it in Vaadin 7 already. Am I missing something?
I couldn't find a way either but I created my own with a custom TextChangeListener. Basically you override the method textChange(TextChangeEvent event) to check if the value is valid. If it's not valid then you delete it. Just be careful to adjust the cursor appropriately. I created a listener for integers (with max/mins), one for doubles, percentages, etc. Basically any kind of number validation you need. The tricky part is managing the cursor position. I wish I had some sample code to show you but I don't have it available on my current computer, but at least this should give you a running start.

Learning Qt: Which methodology to be used for this "advanced UI"?

I am learning Qt5 using PyQt.
My goal is to create a UI with several goals (I will base my need on the screenshot below).
So here are my goals:
My need
Add directories to a list of directories to be scanned (I know how to use QFileDialog.getExistingDirectory for that). For this I'd like to have a "+" button.
When pressed the QFileDialog would open and a new row would be added.
Then I would scan the directory to look for files. It won't be my first implementation but I'd like to have a circular progress bar being displayed during the scan (at the place of the classic progress bar).
When the scan is done, the UI would display the number of files found during the scan. And the progress bar would be replaced by a tick mark icon (not shown on the screenshot...).
At the beginning of each row, I'd like to have a "-" button to delete the row.
My goal is to learn
This is important, I know I am not the first one to have the idea of such a UI.
So I not looking for a third party lib on top of Qt.
My goal is to learn Qt5 (with PyQt) with this example.
But if its unrealistic, please tell me!
My knowledge
Mode View: I implemented some basic model view widgets to display strings, and I understand how to extend the idea to tables or trees.
In this case the number of rows in the table would be handled automatically.
But is it possible to created a table that would display not only strings but also widgets?
Widget Mapper: I read that another methodology is the QDataWidgetMapper. In this case, I would have to deal with creation of news rows by myself, and then I would map data onto them.
But it seems to be a hard and long job.
So, is it a good idea?
So finally could someone tell what is the best direction for that?
I am not looking for code, but since it takes a lots of time to learn new concepts, I'd like to learn and use the correct one before starting coding.
Thank you for your help :)!
After so more searches, I found that I need to use the delegate methodology.
In Qt5 it's QStyledItemDelegate and in Qt4 it's QItemDelegate.
I could find a nice tutorial at the moment, but I started coded it.

How to do chalk style drawing with Qt

I want to use Qt to draw lines in chalk style, as you typically see on a blackboard. Here is an example of what I have in mind:
What is the best way to achieve this rendering style? Do I need to draw a lot of little lines with a special brush, or is there a better way to get the "curvy" style you see in the sample image?
And where is the best place to integrate this? Theoretically it would be ideal to get this underneath QPainter, e.g. in a custom QPaintEngine, so that e.g. all the various QPainter::drawLine calls end up using the chalk style. However, it seems while the QPaintEngine interface looks perfect for this, the class itself isn't meant to be used for this purpose...
Thanks in advance for any help.
Greetings,
Fabian
I have solved the problem in a different way. Using textured brushes didn't provide good results (maybe my fault). QGraphicsEffect was unfortunately not an option since my rendering is not based on QGraphicsView.
What I have done in the end:
Derived an own class from QPainter (i.e. ChalkPainter)
Added a new drawChalkLine() method to ChalkPainter. This method takes the passed line, splits it into smaller chunks and renders these chunks as bezier curves via QPainter::drawPath. For each bezier curve chunk I randomly shift the control point orthogonal to the line.
Next I added additional rendering methods to the ChalkPainter class, such as drawChalkRect(), all internally using the drawChalkLine() method.
This is not the most elegant method since I can't use the QPainter methods directly, but it provides good results for my purpose. Here is an example:
I would start looking in QGraphicsEffect's way.. I think it should be possible to develop such a filter which will produce similar effect..
I'll update in here answer on your comment.
No, QGraphicsEffect can be applied 'per graphics item'. If you have a look on QGraphicsItem you will see that there is a setGraphicsEffect method, so you can design an effect which works on QGraphicsLineItem for example and set it only on lines you want to look chalky..
Important thing is that you don't have to operate on pre-drawn image, you can either make it completely owner-draw item with graphicsEffect (for example make an assumption that effect is only applicable on QGraphicsLineItem) pre-draw it using drawSource() and then modify OR draw it completely from scratch..
I would love to help you with some coding, probably will do it somewhere around next week, since I will need similar thing for project I am working on now.. but physically don't have time next few days..
I'll update an answer with sources link as soon as it's done.
Custom brush also looks really promising..

Drupal 7: How can I create a key/value field(or field group, if that's even possible)?

Let's say I'm creating some app documentation. In creating a content type for functions, I have a text field for name, a box for a general description, and a couple other basic things. Now I need something for storing arguments to the function. Ideally, I'd like to input these as key-value pairs, or just two related fields, which can then be repeated as many times as needed for the given function. But I can't find any way to accomplish this.
The closest I've gotten is an abandonded field multigroup module that says to wait for CCK3, which hasn't even produced an alpha yet as far as I can tell and whose project page makes no obvious mention of this multi-group functionality. I also checked the CCK issue queue and don't think I saw it in there, either.
Is there a current viable way of doing this I'm not seeing? Viable includes "you're thinking of this the wrong way and do X instead." I've considered using a "Long text and summary" field, but that smells hackish and I don't know if I'd be setting myself up for side-effects. I'm new to Drupal.
There is the http://drupal.org/project/field_collection module but it's not yet ready. Right now you would need to implement your entity alas to do this :( not easy.
Not sure how well it would work, because it currently does a bit more (eg, forces to group pairs into categories and the keys need to be predefined) but you might want to have a look at http://drupal.org/project/properties.
You could create a these key-value fields on their own: create 2 regular fields that that can be added as often as needed.
So you have a x fields for the keys and x for the values. If this is only for you or other people it might work OK but usability wise, it's very ugly.
If you need to extract the fields from the function, to display it properly in a page template, you should propably use a different approach. Write the function with its arguemnts in a CCK field and in the template extract them as needed. The arguments are always (depending on language) in () and the different arguments are seperated by , so splitting them would by pretty easy.

QTableWidget, allow to type numbers only

I have a QTableWidget with four columns. I want the user to be able to insert only integers in the first three and a double in the fourth.
I believe that this can be done with delegate, but I have not found relevant examples (only some with QDateTimeEdit).
What should I do?
Look at the documentation for QItemDelegate; it provides a pretty good description on how it can be used.
Since with a delegate, you'll be able to provide your own custom editor, I would suggest that you use a QLineEdit with a validator set using setValidator(). I believe the classes QIntValidator and QDoubleValidator will be perfect in this situation.

Resources