Extending wxComboBox - thin separator line between items

Are you writing your own components and need help with how to set them up or have questions about the components you are deriving from ? Ask them here.
Post Reply
Forbin
Earned a small fee
Earned a small fee
Posts: 21
Joined: Mon Oct 31, 2016 7:26 pm

Extending wxComboBox - thin separator line between items

Post by Forbin »

I need to extend wxComboBox (or develop a combobox-like control) so that I can add one or more thin separator lines between choices, very much like the below:
comboWithSep.jpg
comboWithSep.jpg (5.58 KiB) Viewed 17223 times
Details:
  • I am using wxWidgets 3.0.2, and have no options to use any other version (this is an existing software project with many other dependencies)
  • I am relatively new to wxWidgets but reasonably knowledgable in C++
  • The combo box is text-only and does not need icons or other decorative enhancements
  • I need to build for Windows 7/8.1/10 and Mac OSX 10.x, but not other OSes
I've seen conflicting information as to whether I should overload the OnPaint event handler or not.
Regardless of how I implement this, I need to avoid any labor-intensive approaches if possible.

I would value your recommendations and suggestions!
User avatar
doublemax
Moderator
Moderator
Posts: 19103
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Extending wxComboBox - thin separator line between items

Post by doublemax »

wxComboCtrl allows more customization than wxComboBox:
http://docs.wxwidgets.org/trunk/classwx_combo_ctrl.html

The "combo" sample that comes with wxWidgets shows how to use it.
Use the source, Luke!
Forbin
Earned a small fee
Earned a small fee
Posts: 21
Joined: Mon Oct 31, 2016 7:26 pm

Re: Extending wxComboBox - thin separator line between items

Post by Forbin »

Aha... I'm browsing it now. Thanks!! It looks like it "manually" manages its popup control.

I'm thinking perhaps I could intercept the OnPaint for just the popup control, and be able to draw the dividing line there?
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4182
Joined: Sun Jan 03, 2010 5:45 pm

Re: Extending wxComboBox - thin separator line between items

Post by PB »

Just be aware that IIRC wxComboCtrl (at least on MSW) does not behave like a wxComboBox. For example, there is no support for navigating the items with keyboard at all, i.e. selecting items with cursor keys (Up, Dn, PgUp, PgDn, Home, End) or by typing their first few letters or even closing the pop-up with Esc/Enter etc. All this must be implemented anew (aka copied from wxComboBox).

Maybe just using a regular menu (perhaps something like this) instead may be a better idea...
Forbin
Earned a small fee
Earned a small fee
Posts: 21
Joined: Mon Oct 31, 2016 7:26 pm

Re: Extending wxComboBox - thin separator line between items

Post by Forbin »

PB wrote:Maybe just using a regular menu (perhaps something like this) instead may be a better idea...
Very clever! And it would certainly get me the dividing lines, since menus in both OSX and MSW have them.

Are you saying that I should use the menu for my popup section but build the rest of the control myself, as was done with your SplitButton example? (Obviously using an edit control or whatever so my version looks like a combo box.)

How would doing that differ from using wxComboCtrl, but wrapping the menu object in a class derived from wxComboPopup?

(The existing combo box in the app I"m working on allows you to all the keyboard actions you described; I'm adding an MRU list section to the combo box, and I'm guessing the product manager won't want to lose functionality to gain the divider bar and the MRU.)

Thanks!
--forbin
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4182
Joined: Sun Jan 03, 2010 5:45 pm

Re: Extending wxComboBox - thin separator line between items

Post by PB »

I actually meant using just a pop-up menu with another control as the easiest way to do that. If the control has to look and behave like a combox, you cannot do that then.
Forbin
Earned a small fee
Earned a small fee
Posts: 21
Joined: Mon Oct 31, 2016 7:26 pm

Re: Extending wxComboBox - thin separator line between items

Post by Forbin »

I ended up using wxOwnerDrawnComboBox and just extending the text list class within.
Thanks for the help and advice!
gasko
Earned a small fee
Earned a small fee
Posts: 11
Joined: Mon Apr 13, 2020 11:14 am

Re: Extending wxComboBox - thin separator line between items

Post by gasko »

Could you possibly expand on how you achieved this with wxOwnerDrawnComboBox please? I'm looking to do the same :)
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7449
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Extending wxComboBox - thin separator line between items

Post by ONEEYEMAN »

Hi,
There is a {long withstanding} ticket, requesting this feature in wxWidgets.

If you can post the code, maybe someone will adapt it for inclusion in the library.

Thank you.
Post Reply