Search code examples
c++resizetoolbarwxwidgets

Changing the Height of a wxToolBar


I want to set the height of a toolbar to the same height as it's neighboring tool bar. I'm setting these toolbars up with an .xrc file. Here's what I'm seeing:

enter image description here

And here's my .xrc markup:

<object class="sizeritem">
    <flag>wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL</flag>
    <border>0</border>
    <object class="wxToolBar" name="ID_TOOLBAR">
        <style>wxTB_FLAT|wxTB_HORIZONTAL</style>
        <bitmapsize>32,32</bitmapsize>
        <dontattachtoframe>1</dontattachtoframe>
        <object class="tool" name="ID_TOOL_RUN">
            <bitmap>tool_run.png</bitmap>
            <label>Run</label>
        </object>
        <object class="tool" name="ID_TOOL_PAUSE">
            <bitmap>tool_pause.png</bitmap>
            <label>Puase</label>
        </object>
        <object class="tool" name="ID_TOOL_STOP">
            <bitmap>tool_stop.png</bitmap>
            <label>Stop</label>
        </object>
    </object>
</object>
<object class="sizeritem">
    <flag>wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL</flag>
    <border>0</border>
    <object class="wxToolBar" name="ID_TOOLBAR3">
        <style>wxTB_FLAT|wxTB_HORZ_TEXT|wxTB_NOICONS</style>
        <margins>32,32</margins>
        <dontattachtoframe>1</dontattachtoframe>
        <object class="separator">
        </object>
        <object class="tool">
            <label>Auto Attack</label>
        </object>
    </object>
</object>

I have tried to resize ID_TOOLBAR3 with both margins and bitmapsize neither has any effect. Is there something else I can do?

EDIT: I've also tried using the SetSize to adjust the height in code and I cannot seem to do it. Something is locking it to this small height.


Solution

  • Well an ugly solution seems to be to actually draw the bitmap and the text, but have the bitmap be 0 width and use a transparent 1x1 bitmap: https://i.sstatic.net/tXZKH.png

    I was able to validate this works by:

    1. Removing wxTB_NOICONS from ID_TOOLBAR3's style
    2. Using a 0-width bitmapsize in ID_TOOLBAR3
    3. Adding tXZKH.png to ID_TOOLBAR3's child
    <object class="sizeritem">
        <flag>wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL</flag>
        <border>0</border>
        <object class="wxToolBar" name="ID_TOOLBAR3">
            <style>wxTB_FLAT|wxTB_HORZ_TEXT</style>
            <bitmapsize>0, 32</bitmapsize>
            <dontattachtoframe>1</dontattachtoframe>
            <object class="separator">
            </object>
            <object class="tool">
                <bitmap>tXZKH.png</bitmap>
                <label>Auto Attack</label>
            </object>
        </object>
    </object>
    

    enter image description here