wxtextctrl setvalue/getvalue confusion Topic is solved

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
Emerald2240
Knows some wx things
Knows some wx things
Posts: 30
Joined: Tue Dec 11, 2018 1:38 pm

wxtextctrl setvalue/getvalue confusion

Post by Emerald2240 »

Hello! I'm a beginner in wxwidgets, just started learning it on my own a few weeks ago and decided I wanted to work on my first project: A simple Calculator with onscreen buttons
I was able to make a working prototype that accepted a single number and then a function then another number and then printing the answer in a wxtextctrl widget
I had a slight problem with the onscreen number buttons in as I don't seem to be able to add more than a singlenumberr and then print it on the screen/wxtextctrl of which I use the setvalue/getvalue functions
My question is: is there a way or function which I can use to display more than a single number on the wxtextctrl widget?
Forgive my naivety
Kvaz1r
Super wx Problem Solver
Super wx Problem Solver
Posts: 357
Joined: Tue Jun 07, 2016 1:07 pm

Re: wxtextctrl setvalue/getvalue confusion

Post by Kvaz1r »

Hello. Not sure that I undesrstand what you want to achieve. Maybe you can provide some example with expected and actual output?
For displaying "compound" number you can join into one string several values with some delimeter.
Ruro
Experienced Solver
Experienced Solver
Posts: 83
Joined: Wed May 23, 2007 2:20 pm
Location: Verona, Italy

Re: wxtextctrl setvalue/getvalue confusion

Post by Ruro »

Hello,

Maybe you need AppendText() https://docs.wxwidgets.org/3.1/classwx_ ... aa9640768b
This way you can append more digit to the current number.

Nicola.
Emerald2240
Knows some wx things
Knows some wx things
Posts: 30
Joined: Tue Dec 11, 2018 1:38 pm

Re: wxtextctrl setvalue/getvalue confusion

Post by Emerald2240 »

Kvaz1r wrote:Hello. Not sure that I undesrstand what you want to achieve. Maybe you can provide some example with expected and actual output?
For displaying "compound" number you can join into one string several values with some delimeter.
Thanks for your reply! the thing is I created onscreen buttons 1,2,3,4,5,6,7,8,9
By declaring an Int variable equals to what number you click and then setting that variable to the wxtextctrl widget with the set label function, the problem with this approach is it accepts a single number only
For example I can't click 50 or 590 with the onscreen number buttons without the single number overwriting the next single number
I know this happens as a result of my use of setvalue functions
I want to know if there's a way out of this while using the onscreen buttons
I know I could easily make the input by keyboard but I really find the onscreen buttons a whole more appealing to the eye and due to the fact it is of course a very very basic calculator
here's an example of a code i use with one button
void projectcalciFrame::OnButton8Click(wxCommandEvent& event)
{
int h = 2;
wxString two = wxT("");
two<<h;
TextCtrl1->SetValue(two);
}
forgive my Naivety
Emerald2240
Knows some wx things
Knows some wx things
Posts: 30
Joined: Tue Dec 11, 2018 1:38 pm

Re: wxtextctrl setvalue/getvalue confusion

Post by Emerald2240 »

Ruro wrote:Hello,

Maybe you need AppendText() https://docs.wxwidgets.org/3.1/classwx_ ... aa9640768b
This way you can append more digit to the current number.

Nicola.
Thanks a lot!
I'm not really sure I understand how to port this into my program but I'll try!
Emerald2240
Knows some wx things
Knows some wx things
Posts: 30
Joined: Tue Dec 11, 2018 1:38 pm

Re: wxtextctrl setvalue/getvalue confusion

Post by Emerald2240 »

Thanks for your replies! the thing is I created onscreen buttons 1,2,3,4,5,6,7,8,9
By declaring an Int variable equals to what number you click and then setting that variable to the wxtextctrl widget with the set label function, the problem with this approach is it accepts a single number only
For example I can't click 50 or 590 with the onscreen number buttons without the single number overwriting the next single number
I know this happens as a result of my use of setvalue functions
I want to know if there's a way out of this while using the onscreen buttons
I know I could easily make the input by keyboard but I really find the onscreen buttons a whole more appealing to the eye and due to the fact it is of course a very very basic calculator
here's an example of a code i use with one button
void projectcalciFrame::OnButton8Click(wxCommandEvent& event)
{
int h = 2;
wxString two = wxT("");
two<<h;
TextCtrl1->SetValue(two);
}
forgive my Naivety
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: wxtextctrl setvalue/getvalue confusion

Post by PB »

As ruro has already told you, you need to append the button value to the existing displayed number. I.e., in your example to replace

Code: Select all

TextCtrl1->SetValue(two);
with

Code: Select all

TextCtrl1->AppendText(two);
Emerald2240
Knows some wx things
Knows some wx things
Posts: 30
Joined: Tue Dec 11, 2018 1:38 pm

Re: wxtextctrl setvalue/getvalue confusion

Post by Emerald2240 »

PB wrote:As ruro has already told you, you need to append the button value to the existing displayed number. I.e., in your example to replace

Code: Select all

TextCtrl1->SetValue(two);
with

Code: Select all

TextCtrl1->AppendText(two);
thanks a lot was really having troubles understanding what he meant
Post Reply