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
wxtextctrl setvalue/getvalue confusion Topic is solved
-
- Knows some wx things
- Posts: 30
- Joined: Tue Dec 11, 2018 1:38 pm
Re: wxtextctrl setvalue/getvalue confusion
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.
For displaying "compound" number you can join into one string several values with some delimeter.
Re: wxtextctrl setvalue/getvalue confusion
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.
Maybe you need AppendText() https://docs.wxwidgets.org/3.1/classwx_ ... aa9640768b
This way you can append more digit to the current number.
Nicola.
-
- Knows some wx things
- Posts: 30
- Joined: Tue Dec 11, 2018 1:38 pm
Re: wxtextctrl setvalue/getvalue confusion
Thanks for your reply! the thing is I created onscreen buttons 1,2,3,4,5,6,7,8,9Kvaz1r 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.
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
-
- Knows some wx things
- Posts: 30
- Joined: Tue Dec 11, 2018 1:38 pm
Re: wxtextctrl setvalue/getvalue confusion
Thanks a lot!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.
I'm not really sure I understand how to port this into my program but I'll try!
-
- Knows some wx things
- Posts: 30
- Joined: Tue Dec 11, 2018 1:38 pm
Re: wxtextctrl setvalue/getvalue confusion
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
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
Re: wxtextctrl setvalue/getvalue confusion
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
with
Code: Select all
TextCtrl1->SetValue(two);
Code: Select all
TextCtrl1->AppendText(two);
-
- Knows some wx things
- Posts: 30
- Joined: Tue Dec 11, 2018 1:38 pm
Re: wxtextctrl setvalue/getvalue confusion
thanks a lot was really having troubles understanding what he meantPB 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 replacewithCode: Select all
TextCtrl1->SetValue(two);
Code: Select all
TextCtrl1->AppendText(two);