tags:

views:

196

answers:

1

My application (Microsoft Windows only) is using a wxToolBar with wxTB_HORIZONTAL|wxTB_TEXT|wxTB_HORZ_LAYOUT flags set. All it's buttons/tools have the same width, which is based on the longest text.

I'd like to have buttons with different widths, depending on the tool label's length, just like the Windows native toolbar buttons (created with the BTNS_AUTOSIZE style).

Is there any way to get wxToolBar with buttons that have dynamically calculated width?

+2  A: 

I assume you want this for MS Windows, since you mention the BTNS_AUTOSIZE style.

There is no way to do this with wxToolBar styles or a parameter to AddTool(). I have tried with wxMSW, and the only way to achieve auto-sizing buttons (that I could find) is by changing the wxToolBar::Realize() method in src/msw/tbar95.cpp (src/msw/toolbar.cpp in wxWidgets trunk) to add the BTNS_AUTOSIZE style in the places where the buttons are added. This is a virtual method, so you could always create your own descending toolbar class, copy the Realize() method and change it.

mghie
Thanks a lot. I thought about creating descending class, but wanted to know if there is any simpler solution.
Wacek