Height problem in wxVListBox

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.
Post Reply
tgg_splash
Earned a small fee
Earned a small fee
Posts: 24
Joined: Thu Jan 04, 2018 8:05 am

Height problem in wxVListBox

Post by tgg_splash »

I derive a class named MyVListBox from wxVListBox. I override OnMeasureItem and return the same value for each item. To implement MyVListBox can insert, I call the function EstimateTotalHeight to get corrent height and set window size. I found that there is an empty area in the end of the MyVListBox. Is it a mistake? I read the source and can't find why. The "htmlbox" sample does same thing.
wxWidgets- 3.1.0 visual studio 2015
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Height problem in wxVListBox

Post by doublemax »

OnMeasureItem doesn't include the margins between two items. You get can those with GetMargins().

From the wxVListBox source:

Code: Select all

wxCoord wxVListBox::OnGetRowHeight(size_t line) const
{
    return OnMeasureItem(line) + 2*m_ptMargins.y;
}
Use the source, Luke!
tgg_splash
Earned a small fee
Earned a small fee
Posts: 24
Joined: Thu Jan 04, 2018 8:05 am

Re: Height problem in wxVListBox

Post by tgg_splash »

doublemax wrote:OnMeasureItem doesn't include the margins between two items. You get can those with GetMargins().

From the wxVListBox source:

Code: Select all

wxCoord wxVListBox::OnGetRowHeight(size_t line) const
{
    return OnMeasureItem(line) + 2*m_ptMargins.y;
}

Code: Select all

    // we implement OnGetRowHeight() in terms of OnMeasureItem() because this
    // allows us to add borders to the items easily
    //
    // this function is not supposed to be overridden by the derived classes
    virtual wxCoord OnGetRowHeight(size_t line) const;
I have considered about it. I print the return value of GetMargin and it is zero. I also trid to change the margin by calling SetMargin(). It does not make difference and just make the listbox strange.I prefer this control because by this I can easily deal with custom draw. But the problem makes me confused.
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Height problem in wxVListBox

Post by doublemax »

How big is the empty area?
Can you show your code?
Use the source, Luke!
tgg_splash
Earned a small fee
Earned a small fee
Posts: 24
Joined: Thu Jan 04, 2018 8:05 am

Re: Height problem in wxVListBox

Post by tgg_splash »

doublemax wrote:How big is the empty area?
Can you show your code?
I guess that it's just look like the height of one item.
Attachments
HybirdButton.rar
(10.83 KiB) Downloaded 40 times
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Height problem in wxVListBox

Post by doublemax »

I only had time for a quick look (on my way to work):

Are you talking about the vlistbox in the popup? If yes, I think the size of the vlistbox is more or less ok ( maybe a few pixels off), the empty area is the OperRecordButton at the bottom of the popup. Set its background color to green or something and you'll see it.
Use the source, Luke!
tgg_splash
Earned a small fee
Earned a small fee
Posts: 24
Joined: Thu Jan 04, 2018 8:05 am

Re: Height problem in wxVListBox

Post by tgg_splash »

doublemax wrote:I only had time for a quick look (on my way to work):

Are you talking about the vlistbox in the popup? If yes, I think the size of the vlistbox is more or less ok ( maybe a few pixels off), the empty area is the OperRecordButton at the bottom of the popup. Set its background color to green or something and you'll see it.
I had found the solution. When I calculate the height of the control, I miss the height of border. Then, the control increased the height of an item automatically.
Post Reply