Adding a toolbar is generating a strange result

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
Dan
In need of some credit
In need of some credit
Posts: 1
Joined: Thu Dec 02, 2021 5:39 am

Adding a toolbar is generating a strange result

Post by Dan »

I'm trying to accomplish a very simple task, add a toolbar to an app. I tried the most simple thing I could come up with, but the result is kind of strange, and I was wondering if this is suppose to behave this way or if I'm missing something.

The code is below, note that I even tried to use a native image(commented), but the result was the same.

Code: Select all

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

class MyApp: public wxApp
{
public:
    virtual bool OnInit();
};

class MyFrame: public wxFrame
{
public:
    MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
};

wxIMPLEMENT_APP(MyApp);


bool MyApp::OnInit()
{
    MyFrame *frame = new MyFrame("Simple test", wxPoint(50, 50), wxSize(450, 340) );
    frame->Show( true );
    return true;
}

MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
        : wxFrame(NULL, wxID_ANY, title, pos, size)
{
    // wxToolBar *toolbar = CreateToolBar();
    // toolbar->AddTool(1001, _("New"), wxArtProvider::GetBitmap("wxART_NEW"));
    // toolbar->Realize();
    CreateStatusBar();
    SetStatusText(wxT("Start"));

    wxInitAllImageHandlers();
    wxImage image(wxT("save.png"), wxBITMAP_TYPE_PNG);
    if (image.Ok())
    {
        wxToolBar *toolbar = CreateToolBar();
        toolbar->AddTool(1001, _("New"), image);
        toolbar->Realize();
    }
    else
    {
         SetStatusText(wxT("image not ok"));   
    }
}
The result is here, note that the icon is in the app bar instead in a separate toolbar.
gzXac.png
gzXac.png (56.76 KiB) Viewed 435 times
It was compiled on a macOS Monterey (version 12.0.1), Intel processor.
User avatar
doublemax
Moderator
Moderator
Posts: 19160
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Adding a toolbar is generating a strange result

Post by doublemax »

Which wxWidgets version did you use?

Please try to build and run the "toolbar" sample that comes with wxWidgets.
Use the source, Luke!
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7479
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Adding a toolbar is generating a strange result

Post by ONEEYEMAN »

Hi,
Also, what OSX version you are trying it on?
And did you build it as a Bundle?

Thank you.
Post Reply