wxTextCtrl taking only numbers, wxNumberCtrl?

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
paddle
Knows some wx things
Knows some wx things
Posts: 27
Joined: Sat Oct 12, 2019 4:57 pm

wxTextCtrl taking only numbers, wxNumberCtrl?

Post by paddle » Fri Nov 01, 2019 7:43 am

I'm trying to have a wxtextctrl which accept only numbers, with a method getint() to get the number.
It seems I found just that: viewtopic.php?t=15978
However I tried to add

Code: Select all

#include "wxNumberCtrl.h"
#include "wxNumberCtrl.cpp"
And edited my wxTextCtrl to use wxNumberCtrl class. But on build I have an error :

Code: Select all

C:\wxWidgets-3.1.2\include\wx\rtti.h|165|error: redefinition of 'wxClassInfo wxNumberCtrl::ms_classInfo'|
I guess maybe this wxNumberCtrl dating from 2007 may be broken by recent updates? Feel like this could be added to wxwidget basic stuff as inputing a number is quite usual.

What is the easier way around this?

Kvaz1r
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 222
Joined: Tue Jun 07, 2016 1:07 pm

Re: wxTextCtrl taking only numbers, wxNumberCtrl?

Post by Kvaz1r » Fri Nov 01, 2019 8:19 am

You can use validator for usual wxTextCtrl.

User avatar
doublemax
Moderator
Moderator
Posts: 15069
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxTextCtrl taking only numbers, wxNumberCtrl?

Post by doublemax » Fri Nov 01, 2019 8:52 am

Another option would be a wxSpinCtrl.
Use the source, Luke!

paddle
Knows some wx things
Knows some wx things
Posts: 27
Joined: Sat Oct 12, 2019 4:57 pm

Re: wxTextCtrl taking only numbers, wxNumberCtrl?

Post by paddle » Fri Nov 01, 2019 1:21 pm

From a beginner point of vue, this validator concept seems to add a layer of complexity for a feature that should be easy.

wxSpinCtrl seem more like the thing. But can we type the value or can we use only the arrows? Because I need to enters 64bit values that can be pretty much random, so the arrows are not any help.

wxNumberCtrl looks simple and usefull. Do you think I should post in "General Development" to ask to integrate it in next version ?

User avatar
doublemax
Moderator
Moderator
Posts: 15069
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxTextCtrl taking only numbers, wxNumberCtrl?

Post by doublemax » Fri Nov 01, 2019 1:42 pm

paddle wrote:
Fri Nov 01, 2019 1:21 pm
From a beginner point of vue, this validator concept seems to add a layer of complexity for a feature that should be easy.
It is easy. All you need to do is to create a validator of the correct type and pass it to the wxTextCtrl constructor.
https://docs.wxwidgets.org/trunk/classw ... dator.html
paddle wrote:
Fri Nov 01, 2019 1:21 pm
wxSpinCtrl seem more like the thing. But can we type the value or can we use only the arrows?
Yes, you can also type into it.
paddle wrote:
Fri Nov 01, 2019 1:21 pm
wxNumberCtrl looks simple and usefull. Do you think I should post in "General Development" to ask to integrate it in next version ?
You'd have to post that on the wx-users or wx-dev Google groups where the actual wx developers see it. But they'll probably just tell you to use a validator :)
Use the source, Luke!

paddle
Knows some wx things
Knows some wx things
Posts: 27
Joined: Sat Oct 12, 2019 4:57 pm

Re: wxTextCtrl taking only numbers, wxNumberCtrl?

Post by paddle » Sun Nov 03, 2019 1:40 pm

Thanks for your support again :)

Also I need to manipulate 64bit values. Is there a way to use spinctrl with longlong? Because I cannot enter max value higher than 32bits

User avatar
doublemax
Moderator
Moderator
Posts: 15069
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxTextCtrl taking only numbers, wxNumberCtrl?

Post by doublemax » Sun Nov 03, 2019 3:50 pm

paddle wrote:
Sun Nov 03, 2019 1:40 pm
Also I need to manipulate 64bit values. Is there a way to use spinctrl with longlong? Because I cannot enter max value higher than 32bits
Try wxSpinCtrlDouble with an increment of 1.
https://docs.wxwidgets.org/trunk/classw ... ouble.html
Use the source, Luke!

Post Reply