On Sat, 23 Oct 2021 19:58:37 +0200 Andreas Falkenhahn wrote:
AF> I'm trying to create a wxTextEntryDialog that only accepts numbers
AF> (real and integer).
If you only needed integer numbers, you could use wxNumberEntryDialog. As
it is, you will have to create your own dialog. Luckily, this is really
pretty simple.
AF> So I was trying to associate a
AF> wxFloatingPointValidator with the wxTextEntryDialog like so:
AF>
AF> float fval;
AF> wxFloatingPointValidator<float> val(2, &fval, wxNUM_VAL_ZERO_AS_BLANK);
AF> textEntryDialog.SetTextValidator(val);
AF>
AF> But this doesn't compile because wxFloatingPointValidator doesn't
AF> derive from wxTextValidator so is it not possible to use
AF> wxFloatingPointValidator with wxTextEntryDialog?
No, it isn't. This is because wxTextEntryDialog API is bad, it should take
any validator and not just wxTextValidator, but not only it has this
method, but also GetTextValidator() which returns wxTextValidator too,
which prevents this from being changed easily.
AF> I'm a bit confused because the doc says:
AF>
AF> "This validator can be used with wxTextCtrl or wxComboBox (and potentially any other class implementing wxTextEntry interface)"
AF>
AF> So I'd guess that wxTextEntryDialog is also based on the wxTextEntry
AF> interface so it should allow the use of wxFloatingPointValidator but I
AF> don't see how...
It can't be done currently. I agree that it should be possible, but it's
not exactly a priority and it's easy to work around this by making your own
dialog, as mentioned in the beginning.
Regards,
VZ
--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/