wxBoxSizer(wxHORIZONTAL) in wxFlexGridSizer Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
elmo
Experienced Solver
Experienced Solver
Posts: 56
Joined: Mon Dec 26, 2005 9:23 pm
Location: Poland, Warsaw

wxBoxSizer(wxHORIZONTAL) in wxFlexGridSizer

Post by elmo » Mon Feb 13, 2006 10:08 am

I have some problem with sizers (maybe it's a bug?) - look under second comment

Code: Select all

   wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
      wxFlexGridSizer *participant_info =  new wxFlexGridSizer(EVENT_INFO_FIELD_HIGHEST, 2,5,5);
      participant_info->SetFlexibleDirection(wxVERTICAL);
      participant_info->AddGrowableCol(1, 1);

        //every text is created the same way, without any further modifications -  difference is only in label
         text = new wxStaticText(frame, wxID_ANY, wxT("Nazwa"), wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT, wxT(""));
         [...]
         participant_info->Add(text, 0, wxFIXED_MINSIZE);
         participant_info->Add(input, 1, wxEXPAND);
         [...]
         participant_info->Add(text, 0, wxFIXED_MINSIZE);
         participant_info->Add(choice, 1, wxFIXED_MINSIZE);
         [...]
 
        //and now tricky one -- HERE IS MAIN PROBLEM, above code is given only to be more precise
         text = new wxStaticText(frame, wxID_ANY, wxT("Start"), wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT, wxT(""));

         wxBoxSizer *time_sizer = new wxBoxSizer(wxHORIZONTAL);

            wxDatePickerCtrl *pick_start_date = new wxDatePickerCtrl(frame, wxID_ANY);
            time_sizer->Add(pick_start_date, 0, wxFIXED_MINSIZE);

            //HERE GOES CODE FROM NEXT "CODE" SECTION

         time_sizer->Show(true);

         participant_info->Add(text, 0, wxFIXED_MINSIZE);
         participant_info->Add(time_sizer, 1, wxEXPAND);

      participant_info->Show(true);
      main_sizer->Add(participant_info, 1, wxEXPAND);
And it looks like it should
Image

So now I will expand my wxBoxSizer with two spins:

Code: Select all

            wxSpinCtrl *spin;
            spin = new wxSpinCtrl(frame, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 0, 23, 0);
            spin->SetId(EVENT_INFO_FIELD_START_HOUR);
            time_sizer->Add(spin, 0, wxFIXED_MINSIZE);

            spin = new wxSpinCtrl(frame, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 0, 59, 0);
            spin->SetId(EVENT_INFO_FIELD_START_MINUTES);
            time_sizer->Add(spin, 0, wxFIXED_MINSIZE);
And happens something that I do not know how to deal with... why labels column is so big?
Image
Image

automatix_md
Knows some wx things
Knows some wx things
Posts: 42
Joined: Tue Mar 29, 2005 10:15 am
Location: magdeburg, germany

Post by automatix_md » Thu Feb 16, 2006 1:44 pm

So I had a look on you code - and unfortunately i don't know what could be wrong - looks good -
so I did something similarly with a RAD Tool and sorted the code a little

Code: Select all

void bla::ControlCreation()
{    

    bla* itemPanel1 = this;
    
    //the top sizer of the panel
    wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
    itemPanel1->SetSizer(itemBoxSizer2);
    
    //the flexgrid will be insert into the top sizer
    wxFlexGridSizer* itemFlexGridSizer3 = new wxFlexGridSizer(2, 2, 0, 0);
        itemBoxSizer2->Add(itemFlexGridSizer3, 1, wxGROW|wxALL, 5);
    
        //putting stuff in flex grid
        wxStaticText* itemStaticText4 = new wxStaticText( itemPanel1, wxID_STATIC, _("Static text"), wxDefaultPosition, wxDefaultSize, 0 );
        wxTextCtrl* itemTextCtrl5 = new wxTextCtrl( itemPanel1, ID_TEXTCTRL1, _T(""), wxDefaultPosition, wxDefaultSize, 0 );    
        wxStaticText* itemStaticText6 = new wxStaticText( itemPanel1, wxID_STATIC, _("Static text"), wxDefaultPosition, wxDefaultSize, 0 );    
        wxString* itemChoice7Strings = NULL;
        wxChoice* itemChoice7 = new wxChoice( itemPanel1, ID_CHOICE, wxDefaultPosition, wxDefaultSize, 0, itemChoice7Strings, 0 );
        wxStaticText* itemStaticText8 = new wxStaticText( itemPanel1, wxID_STATIC, _("start"), wxDefaultPosition, wxDefaultSize, 0 );
        
    
        itemFlexGridSizer3->Add(itemStaticText4, 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxALL|wxADJUST_MINSIZE, 5);
        itemFlexGridSizer3->Add(itemTextCtrl5, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5);
        itemFlexGridSizer3->Add(itemStaticText6, 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxALL|wxADJUST_MINSIZE, 5);
        itemFlexGridSizer3->Add(itemChoice7, 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxALL, 5);
        //this is "start"
        itemFlexGridSizer3->Add(itemStaticText8, 0, wxFIXED_MINSIZE);//wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxALL|wxADJUST_MINSIZE, 5);
        

        //creating the boxsizer and add it to flexgrid
        wxBoxSizer* itemBoxSizer9 = new wxBoxSizer(wxHORIZONTAL);
        itemFlexGridSizer3->Add(itemBoxSizer9, 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxALL, 0);
            
            //creating stuff and add it to boxsizer
            wxString* itemChoice10Strings = NULL;
            wxChoice* itemChoice10 = new wxChoice( itemPanel1, ID_CHOICE1, wxDefaultPosition, wxDefaultSize, 0, itemChoice10Strings, 0 );
            wxSpinCtrl* itemSpinCtrl11 = new wxSpinCtrl( itemPanel1, ID_SPINCTRL, _("0"), wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 0, 100, 0 );
            wxSpinCtrl* itemSpinCtrl12 = new wxSpinCtrl( itemPanel1, ID_SPINCTRL1, _("0"), wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 0, 100, 0 );
        
            itemBoxSizer9->Add(itemChoice10, 0, wxALIGN_CENTER_VERTICAL|wxALL|wxFIXED_MINSIZE, 5);
            itemBoxSizer9->Add(itemSpinCtrl11, 0, wxALIGN_CENTER_VERTICAL|wxALL|wxFIXED_MINSIZE, 5);
            itemBoxSizer9->Add(itemSpinCtrl12, 0,  wxALIGN_CENTER_VERTICAL|wxALL|wxFIXED_MINSIZE, 5);


}

maybe this can help you a little

looks like this

Image

eco
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 203
Joined: Tue Aug 31, 2004 7:06 pm
Location: Behind a can of Mountain Dew
Contact:

Re: wxBoxSizer(wxHORIZONTAL) in wxFlexGridSizer

Post by eco » Thu Feb 16, 2006 8:34 pm

elmo wrote:

Code: Select all

      participant_info->SetFlexibleDirection(wxVERTICAL);
      participant_info->AddGrowableCol(1, 1);
I'm not sure if this is the cause of your problem but shouldn't this be wxHORIZONTAL if you are setting growable columns?

eco
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 203
Joined: Tue Aug 31, 2004 7:06 pm
Location: Behind a can of Mountain Dew
Contact:

Post by eco » Thu Feb 16, 2006 8:38 pm

Oh, and I thought I'd mention that, in my opinion, wxGridBagSizer is easier to work with for layouts like these. You can just set controls to span multiple columns/rows. You would, in your case, have 4 columns with the first two rows' controls (the non-static text controls) spanning 3 columns and the third row having each control spanning 1 column.

elmo
Experienced Solver
Experienced Solver
Posts: 56
Joined: Mon Dec 26, 2005 9:23 pm
Location: Poland, Warsaw

Post by elmo » Fri Feb 17, 2006 7:49 am

Thanks both.
I did not know that there exists more than four types of sizers. Maybe I should one more time look at alphabetical list of classes ;]

And yes, the problem was the flag wxVERTICAL. I wasn't sure if I've chosen the right of those two possibilities, but I have no idea why I did not check the other option.

P.S. oh, and I wanted to accept the other post of eco. Just clicked too low.

Post Reply