【发布时间】:2022-01-08 09:44:46
【问题描述】:
我正在尝试完成一个非常简单的任务,将工具栏添加到应用程序。我尝试了我能想到的最简单的方法,但结果有点奇怪,我想知道这是否应该以这种方式运行,或者我是否遗漏了什么。
代码如下,注意我什至尝试使用原生图像(注释),但结果是一样的。
#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"));
}
}
结果在这里,注意图标在应用栏中,而不是在单独的工具栏中。
【问题讨论】:
-
wx 版本? OSX 版本?
toolbar示例适合您吗? -
wxVersion 是 3.1.5 macOs Monterrey 12.0.1 (21A559) 我还没有测试这个例子