Width of wxOwnerDrawnComboBox

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.
ArtDen
Earned a small fee
Earned a small fee
Posts: 10
Joined: Sun Mar 17, 2013 7:01 am

Width of wxOwnerDrawnComboBox

Postby ArtDen » Fri Jul 13, 2018 7:53 am

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:
cb1.png
cb1.png (6.85 KiB) Viewed 86 times

wxChoice make its width correct here.

wxOwnerDrawnComboBox make popup list width correctly, but control's width is not Ok:
cb2.png
cb2.png (5.67 KiB) Viewed 86 times


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);

User avatar
doublemax
Moderator
Moderator
Posts: 12604
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Width of wxOwnerDrawnComboBox

Postby doublemax » Fri Jul 13, 2018 8:50 am

From the docs:
Implementing item drawing and measuring is similar to wxVListBox. Application needs to subclass wxOwnerDrawnComboBox and implement OnDrawItem(), OnMeasureItem() and OnMeasureItemWidth().
Did you do implement OnMeasureItemWidth()? I don't see how the control can know the correct width without it.
Use the source, Luke!

ArtDen
Earned a small fee
Earned a small fee
Posts: 10
Joined: Sun Mar 17, 2013 7:01 am

Re: Width of wxOwnerDrawnComboBox

Postby ArtDen » Fri Jul 13, 2018 8:58 am

I did

PB
Part Of The Furniture
Part Of The Furniture
Posts: 1684
Joined: Sun Jan 03, 2010 5:45 pm

Re: Width of wxOwnerDrawnComboBox

Postby PB » Fri Jul 13, 2018 9:45 am

Assuming that the layout algorithm uses the best size for the control which is implemented as

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());
}


then perhaps this generic implementation may not be the best way when one has a real information about the item widths...


Return to “C++ Development”

Who is online

Users browsing this forum: No registered users and 20 guests