This is the first time I created such a subclass (I only created ones without gui access needs)
The gui is created with wxFormBuilder.
The basic project consists of 3 element:
GUIFrame; which has all member variables of the gui (2 sliders, 1 button and 2 staticTexts),
ClassTestApp; which only has the OnInit function,
ClassTestMain; which has a function m_btn1_OnButtonClick.
m_btn1_OnButtonClick gets the value of the 1st slider and copies the value to the 1st staticText.
Constructor of ClassTestFrame and OnButtobClick function:
Code: Select all
ClassTestFrame::ClassTestFrame(wxFrame *frame) : GUIFrame(frame)
{}
void ClassTestFrame::m_btn1_OnButtonClick( wxCommandEvent& event )
{
Test1 t1(this); // inserted after creating the subclass
t1.VarTest(); // inserted after creating the subclass
int x{m_slider1->GetValue()};
wxString s{};
s << "Slider 1 is set to: " << x;
m_staticText1->SetLabelText(s);
}
Then I used wxFormBuilder to add a subclass called Test1 (Tools - Generate Inherited Class).
In Test1 I have a function call VarTest wich gets the value of the 2nd slider and copies the value to the 2nd staticText.
Constructor in Test1 and function VarTest:
Code: Select all
Test1::Test1( wxWindow* parent ) : GUIFrame( parent )
{}
void Test1::VarTest()
{
int x{m_slider2->GetValue()};
wxString s{};
s << "Slider 2 is set to: " << x;
m_staticText2->SetLabelText(s);
std::cout << s << std::endl; // Console feedback on slidervalue
}
but when running it, the slider 2 value stays on the default value (it does not change after moving)
and the static text remains unchanged.
Searching through forums I found 1 suggestion:
Code: Select all
this->GetParent()->m_staticText1->SetLabelText("test");
I hope someone can help me
RuudH