Custom control problem

Carsten A. Arnholm arnholm at offline.no
Wed Jun 27 14:08:07 PDT 2007


Robert Roebling wrote:
>>>> No idea, really, but what does CheckBox->GetBestSize() return for
>>>> wxMSW and wxGTK? Maybe wxGTK doesn't calculate the size of empty
>>>> check boxes correctly.
>>>
>>> Thanks. I will check this tonight and report back.
>>
>> wxMSW:  CheckBox->GetBestSize()  returns {x=13 y=13}
>> wxGTK:   CheckBox->GetBestSize()  returns {x=23 y=21}
>>
>> So this might be a clue...?
>
> No, they both have a square shape (which is how a check
> box looks like, after all) with different sizes on different
> platforms (which is what can happen on different platforms)
> so this seems correct. I'm afraid you'll have to minimize
> the code that produces the wrong result (like only a dialog
> with your row of checkboxes) and see what makes them appear
> different.

Fair enough :-)

In fact I think I have managed to get a better idea why it is happening, and 
I have now devised a work-around that seems to be fairly effective.

Recap: My control is a wxPanel derivative called wxIoPortCtrl. It contains a 
horizontal wxBoxSizer, containing the wxCheckBox objects. The wxIoPortCtrl 
objects are contained in wxFlexGridSizer cells (owned by a dialog).

What happens is that when I recompute the contents of the wxIoPortCtrl to 
contain 2 instead of 8 checkboxes, the overall size of the owning 
wxFlexGridSizer grid cell seems to be unaffected, even if I call Layout() on 
it. The wxIoPortCtrl  BoxSizer has now 2 slots instead of 8 and the 
wxBoxSizer becomes stretched to fill the wxFlexGridSizer cell area, instead 
of right-aligning the 2 check boxes in the cell.

The work-around is to always use 8 slots in the wxBoxSizer, either 8 
wxCheckBox objects or 6 spacers + 2 wxCheckBox objects:

// do this 6 times before adding the 2 wxCheckBox objects
m_boxSizer->AddSpacer(siz.GetWidth());

// then add 2 wxCheckBox objects
 m_boxSizer->Add(CheckBox,1,......)

So I think it is the wxBoxSizer that causes my confusion. Although my 
work-around seems ok, I wonder if there are other ways to control such 
wxBoxSizer behaviour?

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








More information about the wx-users mailing list