wxWidgets:wxDatePickerCtrl扩展没有明显的原因

时间:2017-01-03 19:50:01

标签: c++ wxwidgets

这是一段将所有元素放在parent(wxPlane)上的代码:

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中的快速示例):

但相反,它看起来像这样:

我究竟做错了什么?也许有旗帜的东西?

这是一个Minimal,Complete和Verifiable示例代码,可以更简单地显示问题:

#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;
}

1 个答案:

答案 0 :(得分: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等)。