开发者

wxWidgets UI has all items gathered upper left corner when first opened

I'm a newbie on wxWidgets and try to design a UI. I'm using Microsoft Visual Studio 2010.

I'm trying to avoid using absolute positions for the UI elements, so I try to do everything with sizers. But when I avoid designing with absolute points my UI looks really bad when I first open the application. But it turns back to what I desire when I resize the window, maximize or just pull a corner of it. But initially every item is gathered up to the left upper corner.

How can I avoid that issue? The code segment is given below:

SimpleUI::SimpleUI(const wxString& title)
       :wxFrame(NULL, -1, title, wxPoint(-1,-1), wxSize(1280, 720))
{
       wxPanel *panel = new wxPanel (this, -1);

       wxColour col1;
       col1.Set(wxT("WHITE"));
       panel->SetBackgroundColour(col1);

       // PNG Files import to the project
       wxImage::AddHandler ( new wxPNGHandler );
       wxBitmap Rseg;
       Rseg.LoadFile("rSeg.png", wxBITMAP_TYPE_PNG);
       wxBitmap Radjust;
       Radjust.LoadFile("rAdjust.png", wxBITMAP_TYPE_PNG);
       wxBitmap Rsurf;
       Rsurf.LoadFile("rSurf.png", wxBITMAP_TYPE_开发者_如何学运维PNG);
       wxBitmap Gseg;
       Gseg.LoadFile("gSeg.png", wxBITMAP_TYPE_PNG);
       wxBitmap no;
       no.LoadFile("no.png", wxBITMAP_TYPE_PNG);

       // Initialization of the Sizers
       wxBoxSizer *vbox = new wxBoxSizer (wxVERTICAL);
       wxBoxSizer *hbox1 = new wxBoxSizer (wxHORIZONTAL);
       seg = new wxBitmapButton(panel, ID_CLICKEDseg, Rseg);
       seg ->SetBitmapDisabled(Gseg);
       Connect(ID_CLICKEDseg, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(SimpleUI::OnClickedSeg));

       adjust = new wxBitmapButton(panel, -1, Radjust);
       surf = new wxBitmapButton(panel, -1, Rsurf);
       nopass = new wxBitmapButton(panel, -1, no, wxPoint(-1, -1), wxDefaultSize, wxBORDER_NONE);

       // Initialization of the Menubar
       menubar = new wxMenuBar;
       file = new wxMenu;
       help = new wxMenu;

       // Menubar build
       menubar->Append(file,wxT("&File"));
       menubar->Append(help,wxT("&Help"));
       SetMenuBar(menubar);

       // Layout and the main assignments

       vbox->Add(-1,30);
       wxBoxSizer *hbox3 = new wxBoxSizer (wxHORIZONTAL);
       hbox3->Add(nopass, 0);
       vbox->Add(hbox3, 0, wxALIGN_LEFT | wxLEFT, 120);

       vbox->Add(-1,50);

       hbox1->Add(seg, 0, wxRIGHT, 120);
       hbox1->Add(adjust, 0);
       vbox->Add(hbox1, 0, wxALIGN_LEFT | wxLEFT, 80);

       vbox->Add(-1,80);
       wxBoxSizer *hbox2 = new wxBoxSizer (wxHORIZONTAL);
       hbox2->Add(surf, 0);
       vbox->Add(hbox2, 0, wxALIGN_LEFT | wxLEFT, 80);


       panel->SetSizer(vbox);
       Center();
}

Thank you.


To solve your immediate problem, add a call to wxSixer::Layout() at the end of the cSimpleUI constructor

vbox->Layout();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜