I did my class derived from wxOwnerDrawnComboBox and overrided OnDrawItem, OnMeasureItemWidth, OnMeasureItem
The problem is the width of control doesn't fit width of text items. Comparison with wxChoice:
wxChoice make its width correct here.
wxOwnerDrawnComboBox make popup list width correctly, but control's width is not Ok:
What I have to do to get correct wxOwnerDrawnComboBox width?
PS: wx 3.0.4, MS Windows, VC
PPS: I filled my control with items before I called GetSizer()->SetSizeHints(this);
Width of wxOwnerDrawnComboBox
Re: Width of wxOwnerDrawnComboBox
From the docs:
Did you do implement OnMeasureItemWidth()? I don't see how the control can know the correct width without it.Implementing item drawing and measuring is similar to wxVListBox. Application needs to subclass wxOwnerDrawnComboBox and implement OnDrawItem(), OnMeasureItem() and OnMeasureItemWidth().
Use the source, Luke!
Re: Width of wxOwnerDrawnComboBox
Assuming that the layout algorithm uses the best size for the control which is implemented as
then perhaps this generic implementation may not be the best way when one has a real information about the item widths...
Code: Select all
wxSize wxOwnerDrawnComboBox::DoGetBestSize() const
{
if ( GetCount() == 0 )
return wxComboCtrlBase::DoGetBestSize();
wxOwnerDrawnComboBox* odc = const_cast<wxOwnerDrawnComboBox*>(this);
// TODO: this class may also have GetHightestItemHeight() and
// GetHightestItem() methods, and so set the whole (edit part + arrow)
// control's height according with this max height, not only max width.
return GetSizeFromTextSize(odc->GetWidestItemWidth());
}