Multiple widget access

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
bandali99
Knows some wx things
Knows some wx things
Posts: 40
Joined: Fri Jul 05, 2019 3:58 pm

Multiple widget access

Post by bandali99 » Tue Aug 20, 2019 10:13 pm

I built this function that when called it created and organizes a custom widget for me. For some reason, I am only able to access the slider when coding it the way I have shown or by using another sizer (slidersizer). But when I change the order and add the slider widget last I am able to use the other widgets but not the slider widgets.

Code: Select all

void customwidgetslider::Oninit(wxPanel* panel, int currentvalue, int maxVal)
{
	id = rand();
	
	playerSizer = new wxBoxSizer(wxHORIZONTAL);
	slider = new singlesliderobj(panel, id, currentvalue, 0, maxVal, wxDefaultPosition, wxSize(-1, 85), wxSL_HORIZONTAL | wxSL_SELRANGE);
	//wxBoxSizer *slidersizer = new wxBoxSizer(wxHORIZONTAL);
	slidercheck = new wxCheckBox(panel, wxID_ANY, "sync");
	TimeText = new wxTextCtrl(panel, wxID_ANY, _("Time"));
	FrameText = new wxTextCtrl(panel, wxID_ANY, _("Frame"));

	playerSizer->Add(slidercheck, 0, wxLEFT);
	playerSizer->Add(TimeText, 0, wxRIGHT);
	playerSizer->Add(FrameText, 0, wxRIGHT);

	/*playerSizer->Add(slidersizer, 0, wxALIGN_CENTER_VERTICAL);*/
	playerSizer->Add(slider, 1, wxEXPAND);

	//Bind(wxEVT_CHECKBOX, &customwidgetslider::SetCheck,this);

}

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

Re: Multiple widget access

Post by doublemax » Wed Aug 21, 2019 5:24 am

For some reason, I am only able to access the slider when coding it the way I have shown or by using another sizer (slidersizer). But when I change the order and add the slider widget last I am able to use the other widgets but not the slider widgets.
Sorry, i didn't fully understand this and / or how it relates to the code you posted.

BTW: Isn't there a SetSizer() call for "playerSizer" missing?
Use the source, Luke!

bandali99
Knows some wx things
Knows some wx things
Posts: 40
Joined: Fri Jul 05, 2019 3:58 pm

Re: Multiple widget access

Post by bandali99 » Wed Aug 21, 2019 3:29 pm

The code above is for a class called customwidgetslider. I used this class in another class called test where I am able to create multiple custom widgets on the frame.
Here is the class for the customwidgetsldier along with the function I call, I changed it from the last post (I was trying different ways)

Code: Select all

customwidgetslider::customwidgetslider(wxPanel *parent, int currentvalue, int maxVal)
	: wxPanel(parent, wxID_ANY, wxDefaultPosition, wxSize(1000,1000))
{
	Oninit(parent, currentvalue, maxVal);

	
}

void customwidgetslider::Oninit(wxPanel* panel, int currentvalue, int maxVal)
{
	id = rand();
	
	playerSizer = new wxBoxSizer(wxHORIZONTAL);
	slider = new singlesliderobj(panel, id, currentvalue, 0, maxVal, wxDefaultPosition, wxSize(-1, 85), wxSL_HORIZONTAL | wxSL_SELRANGE);

	playerSizer->Add(slider, maxVal, wxEXPAND);

	//Bind(wxEVT_CHECKBOX, &customwidgetslider::SetCheck,this);

}
Here is the code for the test class

Code: Select all

test::test(const wxString& title)
	: wxFrame(NULL, wxID_ANY, title, wxDefaultPosition, wxSize(1500, 700))
{
	wxPanel* panel = new wxPanel(this);

	int practice[8] = { 500,1000,1500,2000,2049,2949,1003,3506};
	multi(panel, 1,practice);
	//wxCheckBox* testingcheck = new wxCheckBox(panel, wxID_ANY, "testingcheck");



}

void test::multi(wxPanel* panel ,int n, int* max_array_ordered) {

	wxBoxSizer *mainSizer = new wxBoxSizer(wxHORIZONTAL);
	wxBoxSizer *mediaSizer = new wxBoxSizer(wxVERTICAL);

	for (int i = 0; i < n; i++) {
		
		sliders.push_back(new customwidgetslider(panel, max_array_ordered[i], max_array_ordered[i]));
		
		wxBoxSizer *fullsizer = new wxBoxSizer(wxHORIZONTAL);

		wxBoxSizer *slidersizer = new wxBoxSizer(wxHORIZONTAL);
		wxCheckBox* slidercheck = new wxCheckBox(panel, wxID_ANY, "sync");
		wxTextCtrl* TimeText = new wxTextCtrl(panel, wxID_ANY, _("Time"));
		wxTextCtrl* FrameText = new wxTextCtrl(panel, wxID_ANY, _("Frame"));

		slidersizer->Add(slidercheck, 1, wxLEFT);
		slidersizer->Add(TimeText, 1, wxRIGHT);
		slidersizer->Add(FrameText, 1, wxRIGHT);

		fullsizer->Add(slidersizer, 0, wxALIGN_CENTER_VERTICAL);
		fullsizer->Add(sliders.at(i)->GetPlayerSizer(), 1, wxEXPAND);

		mediaSizer->Add(fullsizer, 1, wxEXPAND);
	}
	
	mainSizer->Add(mediaSizer, 1, wxALIGN_CENTER_VERTICAL | wxALIGN_CENTER_HORIZONTAL);
	panel->SetSizer(mainSizer);


	//Bind(wxEVT_IDLE, &test::onIdle, this);

}
PS: ive added objects and used the sizers in an older project so I know its suppose to work but I did it all in one panel in that project so maybe thats the reason?

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

Re: Multiple widget access

Post by doublemax » Wed Aug 21, 2019 5:23 pm

There is definitely something wrong, but i can't tell you exactly where. I'd need more context. I checked your repo, but it doesn't seem to be updated to these changes.

First of all, i don't see the purpose of customwidgetslider::Oninit(). Why don't you just create the slider in the constructor?

The use of "playerSizer" in Oninit is suspicious, too. A sizer only makes sense if it's inside another sizer or is assigned to a window. But i don't see that anywhere.

In addition to that, "playerSizer" only contains one element, the singlesliderobj. But a sizer that contains only one element is useless 99% of the time, so that doesn't look right either.

I'd guess that all these sliders you create just lie on top of each other.

It's really hard to tell what you intended to do, which makes it hard to tell what's wrong :)
Use the source, Luke!

bandali99
Knows some wx things
Knows some wx things
Posts: 40
Joined: Fri Jul 05, 2019 3:58 pm

Re: Multiple widget access

Post by bandali99 » Wed Aug 21, 2019 7:01 pm

oops sorry I have like different slider projects this one is the n slider widget here is the repo for it https://github.com/fahadbandali/thensliderwidget

bandali99
Knows some wx things
Knows some wx things
Posts: 40
Joined: Fri Jul 05, 2019 3:58 pm

Re: Multiple widget access

Post by bandali99 » Wed Aug 21, 2019 7:05 pm

doublemax wrote:
Wed Aug 21, 2019 5:23 pm
There is definitely something wrong, but i can't tell you exactly where. I'd need more context. I checked your repo, but it doesn't seem to be updated to these changes.

First of all, i don't see the purpose of customwidgetslider::Oninit(). Why don't you just create the slider in the constructor?

The use of "playerSizer" in Oninit is suspicious, too. A sizer only makes sense if it's inside another sizer or is assigned to a window. But i don't see that anywhere.

In addition to that, "playerSizer" only contains one element, the singlesliderobj. But a sizer that contains only one element is useless 99% of the time, so that doesn't look right either.

I'd guess that all these sliders you create just lie on top of each other.

It's really hard to tell what you intended to do, which makes it hard to tell what's wrong :)
my logic for this widget was that I would create a single slider (singlesliderobj). Then I created a class customwidgetslider where the function Oninit would create a sizer, playersizer, that has the slider. After I created a test class which uses the function multi that accesses the playersizer from custom widget and adds it to another sizer (mediasizer) containing the checkbox, timebox and framebox. In the end of this function the mediasizer is added to the mainsizer and is set to the panel.

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

Re: Multiple widget access

Post by doublemax » Wed Aug 21, 2019 8:56 pm

my logic for this widget was that I would create a single slider (singlesliderobj). Then I created a class customwidgetslider where the function Oninit would create a sizer, playersizer, that has the slider. After I created a test class which uses the function multi that accesses the playersizer from custom widget and adds it to another sizer (mediasizer) containing the checkbox, timebox and framebox. In the end of this function the mediasizer is added to the mainsizer and is set to the pane
Sorry, that doesn't tell me more than before :)

Without being able to test this, i won't be able to fix this. There are just too many moving targets.
Use the source, Luke!

bandali99
Knows some wx things
Knows some wx things
Posts: 40
Joined: Fri Jul 05, 2019 3:58 pm

Re: Multiple widget access

Post by bandali99 » Wed Aug 21, 2019 10:25 pm

doublemax wrote:
Wed Aug 21, 2019 8:56 pm
my logic for this widget was that I would create a single slider (singlesliderobj). Then I created a class customwidgetslider where the function Oninit would create a sizer, playersizer, that has the slider. After I created a test class which uses the function multi that accesses the playersizer from custom widget and adds it to another sizer (mediasizer) containing the checkbox, timebox and framebox. In the end of this function the mediasizer is added to the mainsizer and is set to the pane
Sorry, that doesn't tell me more than before :)

Without being able to test this, i won't be able to fix this. There are just too many moving targets.
Yeah youre right, Ive added some more functionality to my widget and updated its repo containing an exe file to run it you could test (a lot to ask for im sorry, just so close to completing the widget). After adding a spinctrl and other buttons, I noticed I could click on those items but for some reason I cannot click the checkbox or textboxes..

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

Re: Multiple widget access

Post by doublemax » Fri Aug 23, 2019 10:18 pm

Took me a while to fix this. The slider is still not behaving correctly when dragging, but i leave that for you to fix ;)
Attachments
sliderwidget.patch
(6.2 KiB) Downloaded 23 times
Use the source, Luke!

Post Reply