wxToolBar and wxTB_BOTTOM - dead space? Topic is solved

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
USB3pt0
In need of some credit
In need of some credit
Posts: 9
Joined: Mon May 04, 2020 3:03 pm

wxToolBar and wxTB_BOTTOM - dead space?

Post by USB3pt0 » Tue May 05, 2020 1:37 pm

Hi,

I'm trying to make a toolbar and put it at the bottom of the frame. The code was generated with wxFormBuilder which shows the toolbar directly under the menu bar, however when compiled and ran in VS2012, it's at the bottom of the window as it should be.

However, it still leaves a blank space the size of the toolbar immediately below the menu bar. On maximizing the window, the space grabs some of the MainMenu text as well as leaving blank space on the left and right of it, the color of the window. A picture is attached.
wxWidgets toolbar error.PNG
wxWidgets toolbar error.PNG (21.08 KiB) Viewed 120 times
The code that generates the toolbar is as follows:

Code: Select all

m_scanSelectToolbar = this->CreateToolBar( wxTB_BOTTOM|wxTB_HORIZONTAL|wxBORDER_RAISED, wxID_SCANSELECTTOOLBAR );
	m_scanSelectToolbar->SetToolSeparation( 0 );
	m_scanSelectToolbar->SetToolPacking( 0 );
	m_scanSelectToolbar->SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE ) );
I'm not sure what to do regarding getting rid of that empty space. The general layout of the window is Menu Bar, Sizer, panels in sizer, then Toolbar. I've tried having it recalculate the layout but nothing seemed to make a difference.

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

Re: wxToolBar and wxTB_BOTTOM - dead space?

Post by PB » Tue May 05, 2020 2:39 pm

I can confirm the bug on Win10 with wxWidgets master. I was sure I already saw it reported and fixed long time ago but could not find that.

It seems that at least on my setup, it can be worked around: setting the wxTB_BOTTOM style flag again after the toolbar was created:

Code: Select all

#include <wx/wx.h>
#include <wx/artprov.h>

// define to 1 to work around the empty space bug
#define TB_AT_BOTTOM_HACK 1

class MainFrame2 : public wxFrame
{
public:
    MainFrame2(wxWindow* parent) : wxFrame(parent, wxID_ANY, "Test")
    {
        wxMenuBar* menuBar = new wxMenuBar();
        menuBar->Append(new wxMenu(), "File");
        SetMenuBar(menuBar);

        (new wxPanel(this))->SetBackgroundColour(*wxRED);

        wxToolBar* toolBar = CreateToolBar(wxTB_BOTTOM | wxTB_HORIZONTAL);
        toolBar->AddTool(wxID_ANY, "", wxArtProvider::GetBitmap(wxART_INFORMATION, wxART_TOOLBAR));
        toolBar->Realize();
#if TB_AT_BOTTOM_HACK
        toolBar->SetWindowStyleFlag(wxTB_BOTTOM);
        toolBar->Realize();
#endif
    }
};

class MyApp : public wxApp
{
public:
    bool OnInit() override
    {
        (new MainFrame2(nullptr))->Show();
        return true;
    }
}; wxIMPLEMENT_APP(MyApp);
EDIT
I noticed that the issue goes away when CreateToolBar() is called without wxTB_HORIZONTAL flag set. This flag is default so there is no difference in toolbar appeareance. I will investigate further or at least create a ticket.

USB3pt0
In need of some credit
In need of some credit
Posts: 9
Joined: Mon May 04, 2020 3:03 pm

Re: wxToolBar and wxTB_BOTTOM - dead space?

Post by USB3pt0 » Tue May 05, 2020 3:12 pm

Yeah, that fixed it and it looks the same. Thanks, hope it's an easy fix for the coders.

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

Re: wxToolBar and wxTB_BOTTOM - dead space?

Post by PB » Tue May 05, 2020 3:55 pm

I have created the ticket, so...
https://trac.wxwidgets.org/ticket/18760

Post Reply