wxStaticLine does not show up in a wxFlexGridSizer

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
deepti
Earned some good credits
Earned some good credits
Posts: 115
Joined: Tue Jul 17, 2018 5:38 pm

wxStaticLine does not show up in a wxFlexGridSizer

Post by deepti »

Hi,

When I use a wxStaticLine within a wxFlexGridSizer, it never gets displayed. But, if i add it directly to a wxBoxSizer, with no other control next to it, it gets displayed correctly. What is it that I am doing wrong?

So, the following code does NOT work:

Code: Select all

	wxFlexGridSizer* fgs_0 = new wxFlexGridSizer(1, 2, 0, 0);
	wxStaticText* InfoText = new wxStaticText(m_DetailsScrolledWindow, wxID_ANY, "Information", wxPoint(-1, 200), wxDefaultSize);
	fgs_0->Add(InfoText);
	wxStaticLine* itemStaticLine12 = new wxStaticLine(m_DetailsScrolledWindow, wxID_STATIC, wxPoint(100, 200), wxDefaultSize, wxLI_HORIZONTAL);
	fgs_0->Add(itemStaticLine12, 0, wxGROW | wxALL, 5);
	
	m_DetailsControlsbox->Add(fgs_0);
The code below works, but the text and the line are shown one below another, as expected.

Code: Select all

wxStaticText* InfoText = new wxStaticText(m_DetailsScrolledWindow, wxID_ANY, "Information", wxPoint(-1, 200), wxDefaultSize);
m_DetailsControlsbox->Add(InfoText);
wxStaticLine* itemStaticLine12 = new wxStaticLine(m_DetailsScrolledWindow, wxID_STATIC, wxPoint(100, 200), wxDefaultSize, wxLI_HORIZONTAL);
m_DetailsControlsbox->Add(itemStaticLine12, 0, wxGROW | wxALL, 5);
However, I want them to be next to each other, which is why wxFlexGridSizer was used. How can this be achieved?
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wxStaticLine does not show up in a wxFlexGridSizer

Post by ONEEYEMAN »

Hi,
What OS?
What wx version?
What toolkit (if applicable)?

Thank you.
deepti
Earned some good credits
Earned some good credits
Posts: 115
Joined: Tue Jul 17, 2018 5:38 pm

Re: wxStaticLine does not show up in a wxFlexGridSizer

Post by deepti »

Hello,

Thanks for your reply.
I see this issue on Windows 10, wxWidgets 3.1.0 version.
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxStaticLine does not show up in a wxFlexGridSizer

Post by doublemax »

Code: Select all

m_DetailsControlsbox->Add(fgs_0);
What type is m_DetailsControlsbox? Depending on whether it's a horizontal or vertical sizer, you probably need to set either the proportion to one or the wxEXPAND flag in that call.

You also need to call AddGrowableCol() for the column that contains the wxStaticLine.
Use the source, Luke!
deepti
Earned some good credits
Earned some good credits
Posts: 115
Joined: Tue Jul 17, 2018 5:38 pm

Re: wxStaticLine does not show up in a wxFlexGridSizer

Post by deepti »

Hi @doublemax,

Thank you for your reply. Sorry for a delayed response since i was off work for quite sometime.

m_DetailsControlsbox is a vertical sizer.

Have tried a few things with wxEXPAND flag, proportion set to 1, AddGrowableCol, etc. But none of them seems to work! .. the wxStaticLine does not appear at all.
Please see code below. Could you help please?

Code: Select all

	wxFlexGridSizer* fgs = new wxFlexGridSizer(1, 2, 0, 0);
	fgs->AddGrowableCol(1);
	wxStaticText* InfoText = new wxStaticText(m_DetailsScrolledWindow, wxID_ANY, "Information", wxPoint(100, 200), wxDefaultSize);
	fgs->Add(InfoText);
	wxStaticLine* itemStaticLine12 = new wxStaticLine(m_DetailsScrolledWindow, wxID_STATIC, wxPoint(150, 200), wxDefaultSize, wxLI_HORIZONTAL);
	//fgs->Add(itemStaticLine12, 0, wxGROW | wxALL, 5);
	fgs->Add(itemStaticLine12, 1 , wxEXPAND);
	
	m_DetailsControlsbox->Add(fgs, 1, wxEXPAND);
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxStaticLine does not show up in a wxFlexGridSizer

Post by doublemax »

It's either a bug in wxFlexGridSizer or wxStaticLine, it only works if you set a fixed size for wxStaticLine:

Code: Select all

wxPanel *panel = new wxPanel(this, wxID_ANY);

wxBoxSizer *vsizer = new wxBoxSizer(wxVERTICAL);

wxFlexGridSizer *fgs = new wxFlexGridSizer(1, 2, 0, 0);
fgs->SetFlexibleDirection( wxBOTH );

wxStaticText *InfoText = new wxStaticText(panel, wxID_ANY, "Information", wxDefaultPosition, wxDefaultSize);
fgs->Add(InfoText);

wxStaticLine *itemStaticLine12 = new wxStaticLine(panel, wxID_STATIC, wxDefaultPosition, wxSize(200,1), wxLI_HORIZONTAL);
fgs->Add(itemStaticLine12, 1, wxALIGN_CENTRE_VERTICAL );

fgs->AddGrowableCol(1);
vsizer->Add(fgs, 1, wxEXPAND);

panel->SetSizer(vsizer);
Use the source, Luke!
deepti
Earned some good credits
Earned some good credits
Posts: 115
Joined: Tue Jul 17, 2018 5:38 pm

Re: wxStaticLine does not show up in a wxFlexGridSizer

Post by deepti »

thank you so much.. specifying a size works! :)
Post Reply