Custom control problem
Carsten A. Arnholm
arnholm at offline.no
Mon Jun 25 14:19:31 PDT 2007
Carsten A. Arnholm wrote:
> Now I am going to make it more general, i.e. allow for a variable
> number of pins/checkboxes.
I have a follow-up question on this.
I have made my custom control class and it seems to work, except for some
layout oddities, here is a dialog that uses the control 5 times, shown for
cases with 8 and 2 checkboxes in the custom control:
<http://www.arnholm.org/tmp/wxIoPortCtrl_dialog.jpg>
I.e. I am able to populate the control with different number of checkboxes,
but the layout of the result isn't entirely as expected (right adjusted),
and I am not sure where/how it should be fixed. For the case where I use 8
checkboxes it seems ok, but when I use only two, I get left-adjusted boxes
on XP and spread out boxes on Linux/Kubuntu.
Here is how I populate the check boxes in a horizontal wxBoxSizer:
void wxIoPortCtrl::CreatePins(const wxString& flags)
{
ClearPins();
int number = flags.length();
// reserve space in vector.
// Not strictly required, but more optimal
m_boxes.reserve(number);
wxSize siz = wxSize(14,-1);
// traverse string and create controls
for(int ibox=0;ibox<number;ibox++) {
// create checkbox with proper initial value
wxCheckBox* CheckBox = new wxCheckBox(this,
wxNewId(),wxEmptyString,
wxDefaultPosition, siz,0,
wxDefaultValidator,_T("ID_CHECKBOX1"));
if(flags.at(ibox) == wxT('0')) CheckBox->SetValue(false);
else CheckBox->SetValue(true);
// add box to sizer and our vector
m_boxSizer->Add(CheckBox,1,wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL,5);
m_boxes.push_back(CheckBox);
}
// recompute the control layout
this->SetSizer(m_boxSizer);
m_boxSizer->Fit(this);
m_boxSizer->SetSizeHints(this);
Layout();
}
I also call Layout(); in the dialog after this call.
Any ideas why I get different layout results?
--
Carsten A. Arnholm
http://arnholm.org/
N59.776 E10.457
More information about the wx-users
mailing list