Custom control problem

Carsten A. Arnholm arnholm at offline.no
Sun Jun 24 04:03:15 PDT 2007


Hello,

I am using wxWidgets 2.8.4 , Code::Blocks/wxSmith
Compiler: VC2005 Express (win) and GCC (Linux)

I am trying to make a custom control that consists of a horizontal 
wxBoxSizer containing a series of unlabeled checboxes, i.e. like this 
<http://www.arnholm.org/tmp/wxIoPortCtrl.jpg>

This is supposed to represent the pins of an IO port, and the user shall be 
able to check/uncheck each pin as required. I was able to make a wxPanel as 
shown using the wxSmith tool.

Now I am trying to make a custom control out of this, but I am having 
difficulties. I get a reasonably sized control, but it has no visible 
contents (there should be 8 checkboxes as shown). Maybe you can help me 
identify what I am doing wrong.

I have derived a class like this
class wxIoPortCtrl : public wxControl

The class contains a wxBoxSizer and a series of wxCheckBoxes. In the 
wxIoPortCtrl constructor, I do

wxIoPortCtrl::wxIoPortCtrl(wxWindow* parent,
                           wxWindowID id,
                           const wxPoint& pos,
                           const wxSize& size,
                           long style,
                           const wxValidator& validator,
                           const wxString& name
                           )
: wxControl(parent,id,pos,size,style,validator,name)
{
     BoxSizer1 = new wxBoxSizer(wxHORIZONTAL);

     CheckBox1 = new wxCheckBox(this, ID_CHECKBOX1, wxEmptyString, 
wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, 
_T("ID_CHECKBOX1"));

    BoxSizer1->Add(CheckBox1 ,1 ,wxTOP |wxBOTTOM| wxALIGN_CENTER_HORIZONTAL 
|wxALIGN_CENTER_VERTICAL ,5);

   // .... etc. for check boxes 2 to 8

  SetSizer(BoxSizer1);
  BoxSizer1->Fit(this);
  BoxSizer1->SetSizeHints(this);
  BoxSizer1->RecalcSizes();
  BoxSizer1->Layout();
}

In the application code, i am trying to use it in a cell of a 
wxFlexGridSizer

 Custom1 = new wxIoPortCtr(this, ID_CUSTOM1, wxDefaultPosition, 
wxDefaultSize,0, wxDefaultValidator, _T("ID_CUSTOM1"));

 FlexGridSizer1->Add(Custom1, 1, wxALL| wxEXPAND |wxALIGN_CENTER_HORIZONTAL 
|wxALIGN_CENTER_VERTICAL,5);

But as noted, I cannot see any of the check boxes, just the expanded control 
that looks like a sunken panel.

What do I need to do to get this to work?

-- 
Carsten A. Arnholm
http://arnholm.org/
N59.776 E10.457 








More information about the wx-users mailing list