Search code examples
c++wxwidgets

wxSizer and wxStaticBitmap ignore minimum size


Wizard::Wizard( wxWindow* parent, const wxString& archive )
: wxWizard(parent, wxID_ANY, _("Wizard"))
{    
    this->SetSizeHints( wxSize( -1,-1 ), wxDefaultSize );

    wxWizardPageSimple* rcModWizPageSelect = new wxWizardPageSimple( this );
    m_pages.Add( rcModWizPageSelect );

    wxBoxSizer* bSizer1;
    bSizer1 = new wxBoxSizer( wxVERTICAL );

    m_bitmap2 = new wxStaticBitmap( rcModWizPageSelect, wxID_ANY, wxBitmap( wxT("data/img.jpg"), wxBITMAP_TYPE_ANY ), wxDefaultPosition, wxDefaultSize, 0 );
    m_bitmap2->SetMinSize( wxSize( 586,192 ) );

    bSizer1->Add( m_bitmap2, 0, wxALL|wxEXPAND|wxFIXED_MINSIZE, 5 );

    wxStaticBoxSizer* sbSizer1;
    sbSizer1 = new wxStaticBoxSizer( new wxStaticBox( rcModWizPageSelect, wxID_ANY, _("Select Archive") ), wxVERTICAL );

    rcModArchivePicker = new wxFilePickerCtrl( rcModWizPageSelect, wxID_ANY, wxEmptyString, _("Select a file"), wxT("*.zip"), wxDefaultPosition, wxDefaultSize, wxFLP_DEFAULT_STYLE|wxFLP_FILE_MUST_EXIST|wxFLP_OPEN );
    sbSizer1->Add( rcModArchivePicker, 0, wxALL|wxEXPAND, 5 );

    bSizer1->Add( sbSizer1, 1, wxALL|wxEXPAND, 5 );

    rcModWizPageSelect->SetSizer( bSizer1 );
    rcModWizPageSelect->Layout();
    bSizer1->Fit( rcModWizPageSelect );
    wxWizardPageSimple* rcModWizPageProgress = new wxWizardPageSimple( this );
    m_pages.Add( rcModWizPageProgress );

    wxBoxSizer* bSizer2;
    bSizer2 = new wxBoxSizer( wxVERTICAL );

    m_bitmap1 = new wxStaticBitmap( rcModWizPageProgress, wxID_ANY, wxBitmap( wxT("data/img.jpg"), wxBITMAP_TYPE_ANY ), wxDefaultPosition, wxDefaultSize, 0 );
    m_bitmap1->SetMinSize( wxSize( 586,192 ) );

    bSizer2->Add( m_bitmap1, 0, wxALL|wxEXPAND|wxFIXED_MINSIZE, 5 );

    wxStaticBoxSizer* sbSizer2;
    sbSizer2 = new wxStaticBoxSizer( new wxStaticBox( rcModWizPageProgress, wxID_ANY, _("Please Wait") ), wxVERTICAL );

    rcModInstallProgress = new wxGauge( rcModWizPageProgress, wxID_ANY, 100, wxDefaultPosition, wxDefaultSize, wxGA_HORIZONTAL|wxGA_SMOOTH );
    rcModInstallProgress->SetValue( 0 ); 
    sbSizer2->Add( rcModInstallProgress, 0, wxALL|wxEXPAND, 5 );

    bSizer2->Add( sbSizer2, 1, wxALL|wxEXPAND, 5 );

    rcModWizPageProgress->SetSizer( bSizer2 );
    rcModWizPageProgress->Layout();
    bSizer2->Fit( rcModWizPageProgress );

    this->Centre( wxBOTH );

    for ( unsigned int i = 1; i < m_pages.GetCount(); i++ )
    {
        m_pages.Item( i )->SetPrev( m_pages.Item( i - 1 ) );
        m_pages.Item( i - 1 )->SetNext( m_pages.Item( i ) );
    }
}

I try to have a nice Wizard Dialog, but the minimum size gets ignored and the overall frame is much smaller than my image is. The image has a size of 586x192.

The preview looks nice in wxFormBuilder but the generated Code looks totally different. Here 2 images: https://i.sstatic.net/tbOzP.png https://i.sstatic.net/B3vVf.png

Can anyone help me with this?


Solution

  • I ran into the same issue and was able to work around it by calling SetItemMinSize() on the sizer as follows:

    sizer->Add(control, 0, 0, 0);
    sizer->SetItemMinSize(control, 150, -1);