Reputation: 799
I'm basically trying to make a simple dialog. The problem with it is, that no matter what i do with the help of the wxGridbagsizer, the buttons always appear on the left corner (over each other).
Code snippet:
wxPanel* panel = new wxPanel(this,-1);
wxButton* b1 = new wxButton(panel,wxID_ANY,L"OK",wxDefaultPosition,wxDefaultSize,0);
wxButton* b2 = new wxButton(panel,wxID_ANY,L"Cancel",wxDefaultPosition,wxDefaultSize,0);
gbs->Add(b1,wxGBPosition(1,1));
gbs->Add(b2,wxGBPosition(2,2));
gbs->Fit(panel);
Upvotes: 0
Views: 1226
Reputation: 20492
The sizer layout is not being executed. It is hard to be sure what is wrong, because your code snippet leaves out so much - for example I assume you are calling the sizer's constructor but you do not show the code. Anyway, I expect the problem is that you have not told the panel about your sizer.
panel->SetSizer( gbs );
Upvotes: 2
Reputation: 860
Try to use DialogBlocks and see what code it generates to understand the workflow of usage of grid bag sizer.
void Yarrr1::CreateControls()
{
////@begin Yarrr1 content construction
Yarrr1* itemPanel1 = this;
wxGridBagSizer* itemGridBagSizer2 = new wxGridBagSizer(0, 0);
itemGridBagSizer2->SetEmptyCellSize(wxSize(10, 20));
itemPanel1->SetSizer(itemGridBagSizer2);
wxButton* itemButton3 = new wxButton( itemPanel1, ID_BUTTON6, _("Button"), wxDefaultPosition, wxDefaultSize, 0 );
itemGridBagSizer2->Add(itemButton3, wxGBPosition(0, 0), wxGBSpan(1, 1), wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5);
wxButton* itemButton4 = new wxButton( itemPanel1, ID_BUTTON7, _("Button"), wxDefaultPosition, wxDefaultSize, 0 );
itemGridBagSizer2->Add(itemButton4, wxGBPosition(1, 1), wxGBSpan(1, 1), wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5);
////@end Yarrr1 content construction
}
Produces http://screencast.com/t/mANmpGmGb20
Upvotes: 1