Example 1 (real situation).
I have a complicated frame (built using wxSizers in wxSmith) containing wxStaticBitmap with some initial size (see screenshot here: http://s58.radikal.ru/i159/1109/fa/07ad11a9486a.jpg ). Everything is all right until I change its size - either by SetBitmap() (giving bitmap of another size) or manually using SetSize() function. After such operation, my frame looks like this: http://s46.radikal.ru/i113/1109/af/a540369c449c.jpg .
Documentation tells me I need to call Layout() on sizer to resize properly. This doesn't helps at all.
Proportion properties in the last sizer's children are all set to 0.
Example 2 (simplified case): to find out how I can solve this, I've made a new simple application with the next structure:
-> BoxSizer1 (horizontal):
-> wxStaticBitmap (initial size 90x90, proportion 0)
-> BoxSizer2 (vertical, proportion 0):
-> (two buttons)
Here is its source code (TestMain.cpp):
Code: Select all
TestDialog::TestDialog(wxWindow* parent,wxWindowID id)
{
//(*Initialize(TestDialog)
Create(parent, id, _("wxWidgets app"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE, _T("id"));
BoxSizer1 = new wxBoxSizer(wxHORIZONTAL);
sb = new wxStaticBitmap(this, ID_STATICBITMAP1, wxNullBitmap, wxDefaultPosition, wxSize(90,90), 0, _T("ID_STATICBITMAP1"));
BoxSizer1->Add(sb, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
BoxSizer2 = new wxBoxSizer(wxVERTICAL);
Button1 = new wxButton(this, ID_BUTTON1, _("About"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON1"));
BoxSizer2->Add(Button1, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 4);
StaticLine1 = new wxStaticLine(this, ID_STATICLINE1, wxDefaultPosition, wxSize(10,-1), wxLI_HORIZONTAL, _T("ID_STATICLINE1"));
BoxSizer2->Add(StaticLine1, 0, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 4);
Button2 = new wxButton(this, ID_BUTTON2, _("Quit"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON2"));
BoxSizer2->Add(Button2, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 4);
BoxSizer1->Add(BoxSizer2, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 4);
SetSizer(BoxSizer1);
BoxSizer1->Fit(this);
BoxSizer1->SetSizeHints(this);
Connect(ID_BUTTON1,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&TestDialog::OnAbout);
Connect(ID_BUTTON2,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&TestDialog::OnQuit);
//*)
}
void TestDialog::OnAbout(wxCommandEvent& event)
{
wxBitmap b(128,128);
sb->SetBitmap(b);// this really changes sb's size, but does not changes its appearance
sb->SetSize(i.sx,i.sy);// whatever I use previous line or this one - they both changes sb's size
//sb->InvalidateBestSize();// I had tries this too - with no result
sb->SetSize(-1,-1,128,128);// force set size - no result too
BoxSizer1->Layout();// this does NOT helps, too !
}
Just created frame screenshot: http://s004.radikal.ru/i205/1109/30/b600ee64f0f0.jpg
After pressing the button: http://s45.radikal.ru/i109/1109/92/0f6bd12a28df.jpg
(There is a garbage inside wxBitmap b after creation; I don't care about it now)
All proportion properties are set to 0.
The questions are:
1) Why BoxSizer does not resizes ? What can I do to make it resize properly ?
2) In example 1 my wxStaticBitmap expanded to bitmap size and shown that bitmap, but in example 2 its visual size was not changed. Why ? (sorry, example 1 code is too large to post it here, but I had checked everything out and found no difference in creation method and properties (such as proportion)).
P.S: wxWidgets version: 2.8.12