-
-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prefix and Suffix properties for MLDoubleSpinBox #1
Comments
Hi, thanks for chiming in. Yes, this is on the list/in the works... the "tricksy" part is not having the prefix/suffix editable, and likewise for the cursor to go in the right place when item is focused (eg. you don't want to have entry after the suffix). I believe this means using an input mask, or at least that would be the simplest method I can think of. Of course you can specify an input mask already, but it will definitely be nice to add pre-baked |
+ Add prefix and suffix properties (see notes on limitations, see issue #1); + Add cleanText property and getCleanText(); + Add new RegExp-based validator as an option; + Add util functions for escaping RegEx and input mask strings.
Well, my "tricksy" part turned out to be more difficult than expected. The input mask technique does work but it is somewhat awkward to use. I did add basic prefix/suffix support, pretty much as you described in the first post (just append and strip), but in editable spin boxes it has the issue I mentioned with the cursor/editing. A user can start typing before/after/in the middle of a prefix/suffix. Works nicely on non-editable ones. I also added a testing page (which helped find/fix other bugs), and in there I implemented an MLDoubleSpinBox subclass with prefix/suffix and an input mask. This works, but I'm not sure it makes sense to implement in the main class because the input mask has to be very specific, and I'm just not sure it's possible to cover all the possible use cases elegantly. The real solution is to use a custom QValidator that is aware of the prefix/suffix, which is exactly what the Controls 1 SpinBox does (QQuickSpinBoxValidator1). It would be tempting to just import that validator and use it, but Controls 1 are deprecated plus I don't want to get them mixed in here anyway. But one could use that if one wanted, I think it would just "plug into" the MLDoubleSpinBox as a custom So eventually I'd like to add a custom C++-based validator (perhaps make it optional to use). Although at some point it will probably make sense to back the whole MLDoubleSpinBox with a C++ base, probably abstracted just like QAbstractSpinBox. Why the Qt folks didn't do this with Controls 2 in the first place I don't know (the whole issue wouldn't really exists if they had used a I'll keep this issue open as a reference until a better solution is found. |
Wow! Very nice analysis! |
Your implementation of the DoubleSpinBox for Qt Quick Controls 2 is very interesting. Thanks!
But in order to port code using Qt Quick Controls 1, one would need the support for the prefix and suffix properties.
As mentioned in the doc: prefix and suffix.
I have added it to the floating point SpinBox example from Qt Quick Controls 2 doc like this:
The text was updated successfully, but these errors were encountered: