How to resize parent on wxCollapsiblePane expansion

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
mmead
In need of some credit
In need of some credit
Posts: 1
Joined: Tue Jun 08, 2021 7:30 pm

How to resize parent on wxCollapsiblePane expansion

Post by mmead » Tue Jun 08, 2021 8:24 pm

Hi,

I am new to using wxWidgets. I am having some difficulty wrapping my head around how to properly handle wxCollapsiblePane expand/collapse events.

The main issue I am having is that, after collapsing the pane, the pane remains the same size as it did when it was fully expanded.

Expanded
Screenshot from 2021-06-08 13-19-29.png
Screenshot from 2021-06-08 13-19-29.png (6.21 KiB) Viewed 291 times
Collapsed
Screenshot from 2021-06-08 13-22-21.png
Screenshot from 2021-06-08 13-22-21.png (4.05 KiB) Viewed 291 times
I've pasted my code below. I am laying out the pane children in a wxFlexGridSizer and binding a custom event handler to wxEVT_COLLAPSIBLEPANE_CHANGED.

Code: Select all

	auto pane = this->GetPane();
	auto pane_sizer = new wxFlexGridSizer(2, 5, 5);

	pane_sizer->AddSpacer(3);
	pane_sizer->AddSpacer(3);

	m_row_0 = new wxStaticText(pane, wxID_ANY, wxEmptyString, wxDefaultPosition, this->GetTextExtent(wxT("XXXXXXXXXXXX")));
	pane_sizer->Add(new wxStaticText(pane, wxID_ANY, wxT("Row 0:")), 1, wxEXPAND, 2);
	pane_sizer->Add(m_row_0, 1, wxALIGN_LEFT, 2);

	m_row_1 = new wxStaticText(pane, wxID_ANY, wxEmptyString, wxDefaultPosition, this->GetTextExtent(wxT("XXXXXXXXXXXX")));
	pane_sizer->Add(new wxStaticText(pane, wxID_ANY, wxT("Row 1:")), 1, wxEXPAND, 2);
	pane_sizer->Add(m_row_1, 1, wxALIGN_LEFT, 2);

	m_row_2 = new wxStaticText(pane, wxID_ANY, wxEmptyString, wxDefaultPosition, this->GetTextExtent(wxT("XXXXXXXXXXXX")));
	pane_sizer->Add(new wxStaticText(pane, wxID_ANY, wxT("Row 2:")), 1, wxEXPAND, 2);
	pane_sizer->Add(m_row_2, 1, wxALIGN_LEFT, 2);

	m_row_3 = new wxStaticText(pane, wxID_ANY, wxEmptyString, wxDefaultPosition, this->GetTextExtent(wxT("XXXXXXXXXXXX")));
	pane_sizer->Add(new wxStaticText(pane, wxID_ANY, "Row 3:"), 1, wxEXPAND, 2);
	pane_sizer->Add(m_row_3, 1, wxALIGN_LEFT, 2);

	m_row_4 = new wxStaticText(pane, wxID_ANY, wxEmptyString, wxDefaultPosition, this->GetTextExtent(wxT("XXXXXXXXXXXX")));
	pane_sizer->Add(new wxStaticText(pane, wxID_ANY, wxT("Row 4:")), 1, wxEXPAND, 2);
	pane_sizer->Add(m_row_4, 1, wxALIGN_LEFT, 2);

	pane_sizer->AddSpacer(3);
	pane_sizer->AddSpacer(3);

	pane->SetSizer(pane_sizer);
	pane_sizer->SetSizeHints(this);
	
	this->Bind(wxEVT_COLLAPSIBLEPANE_CHANGED, [=](wxCollapsiblePaneEvent&) {
		this->Fit();
	});

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

Re: How to resize parent on wxCollapsiblePane expansion

Post by doublemax » Wed Jun 09, 2021 5:19 am

As the code does not compile and is out of context: Did you check the "collpane" sample that comes with wxWidgets?
Use the source, Luke!

Post Reply