2017-01-03 21 views
0

這裏有一段代碼,把對parent(wxPlane)中的所有元素:wxWidgets的:wxDatePickerCtrl擴大沒有明顯理由

parent->DestroyChildren(); 
wxBoxSizer* EntrySizer=new wxBoxSizer(wxVERTICAL); 
    EntryTitle = new wxStaticText(parent, wxID_ANY, title, wxDefaultPosition, wxDefaultSize, 0); 
    EntryTitle->Wrap(-1); 
    EntrySizer->Add(EntryTitle, 0, wxALL|wxALIGN_CENTER_HORIZONTAL, 5); 

    wxBoxSizer* ValueSizer=new wxBoxSizer(wxHORIZONTAL); 
     Value_ = new wxStaticText(parent, wxID_ANY, wxT("Значение:"), wxDefaultPosition, wxDefaultSize, 0); 
     Value_->Wrap(-1); 
     ValueSizer->Add(Value_, 1, wxALL|wxALIGN_CENTER_VERTICAL, 5); 

     wxDateTime t;t.ParseISODate(strvalue); 
     Value = new wxDatePickerCtrl(parent, wxID_ANY, t); 
     ValueSizer->Add(Value, 1, wxALL|wxALIGN_CENTER_VERTICAL, 5); 
    EntrySizer->Add(ValueSizer, 1, wxEXPAND, 5); 

    EntrySizer->Add(0, 0,1, wxEXPAND, 5); 
parent->SetSizer(EntrySizer); 
parent->Layout(); 

Value->Bind(wxEVT_DATE_CHANGED,DateEntry::Edit,this); 
Value->SetFocus(); 

它應該是這樣的(簡單的例子在wxFormBuilder):

但相反,它看起來像這樣:

我做錯了什麼?也許有旗子的東西?

這裏是一個最小的,完整的,並且可驗證示例代碼更簡單地示出了該問題:

#include <wx/wx.h> 
#include <wx/app.h> 
#include <wx/datectrl.h> 

class cApp : public wxApp 
{ 
public: 
    virtual bool OnInit(); 

}; 

class cFrame: public wxFrame 
{ 
public: 
    cFrame(wxFrame *frame, const wxString& title) 
     : wxFrame(frame, -1, title, 
        wxPoint(-1,-1),wxSize(600,600)) 
    { 
     wxBoxSizer* ValueSizer = 
      new wxBoxSizer(wxHORIZONTAL); 
     wxDatePickerCtrl * Value = 
      new wxDatePickerCtrl(this, wxID_ANY, wxDefaultDateTime); 
     ValueSizer->Add(Value, 0, wxALL, 5); 

     SetSizer(ValueSizer); 
     Layout(); 
    } 
}; 

IMPLEMENT_APP(cApp); 

bool cApp::OnInit() 
{ 
    cFrame* frame = 
     new cFrame(0L, _("so41451250")); 
    frame->Show(); 

    return true; 
} 
+0

試試這個:ValueSizer-> Add(Value,0,wxEXPAND,5); – Igor

+0

Nah,同樣的事情。 –

回答

0

一種可能的方案是直接設置wxDatePickerCtrl的大小。並按照Igor的建議在sizer的「添加」功能中設置比例= 0。

#include <wx/wx.h> 
#include <wx/app.h> 
#include <wx/datectrl.h> 

class cApp : public wxApp 
{ 
public: 
    virtual bool OnInit(); 
}; 

class cFrame: public wxFrame 
{ 
public: 
    cFrame(wxFrame *frame, const wxString& title) 
     : wxFrame(frame, -1, title, wxPoint(-1, -1), wxSize(400, 400)) 
    { 
     wxBoxSizer* EntrySizer = new wxBoxSizer(wxVERTICAL); 
     wxStaticText *EntryTitle = new wxStaticText(this, wxID_ANY, title, 
                wxDefaultPosition, 
                wxDefaultSize, 0); 
     EntrySizer->Add(EntryTitle, 0, wxALL|wxALIGN_CENTER_HORIZONTAL, 5); 

     wxBoxSizer* ValueSizer = new wxBoxSizer(wxHORIZONTAL); 
     wxStaticText *Value_ = new wxStaticText(this, wxID_ANY, wxT("Значение:"), 
               wxDefaultPosition, wxDefaultSize, 0); 
     ValueSizer->Add(Value_, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5); 
     wxDatePickerCtrl *Value = new wxDatePickerCtrl(this, wxID_ANY, 
                 wxDefaultDateTime, 
                 wxDefaultPosition, 
                 wxSize(85, 23)); 
     ValueSizer->Add(Value, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5); 

     EntrySizer->Add(ValueSizer, 1, wxEXPAND, 5); 
     EntrySizer->Add(0, 0, 1, wxEXPAND, 5); 
     SetSizer(EntrySizer); 
     Layout(); 
    } 
}; 

IMPLEMENT_APP(cApp); 

bool cApp::OnInit() 
{ 
    cFrame* frame = new cFrame(0L, wxT("Дата обследования")); 
    frame->Show(); 
    return true; 
} 

Screenshot.

我不知道,但是,爲什麼有的得到控制沒有理由(即當比例= 0等)擴展。