wxPopupTransientWindow 没有正确显示内容
wxPopupTransientWindow not showing content correctly
我正在创建一个 C++ wxWidgets 计算器应用程序。我正在实现三角函数,为了节省 space,我在一个按钮中重新组合了所有这些函数。如果您右键单击该按钮,则会创建一个弹出窗口,其中包含所有功能的按钮。我正在为此工作使用派生的 wxPopupTransientWindow class,问题是按钮显示不正确。
这是我的代码:
expandMenu.h
#include "wx/wx.h"
#include "wx/popupwin.h"
struct expandMenuInfo
{
const wxString& label;
wxWindowID id;
expandMenuInfo(const wxString& l, wxWindowID i)
: label{l}
, id{i}
{}
};
class expandMenu : public wxPopupTransientWindow
{
wxWindow* panel;
wxBoxSizer* sizer;
public:
expandMenu(wxWindow* parent, wxPoint pos, std::vector<expandMenuInfo> buttons);
~expandMenu();
};
expandMenu.cpp
#include "expandMenu.h"
// PANNELLO ESTENSIONE
expandMenu::expandMenu(wxWindow* parent, wxPoint pos, std::vector<expandMenuInfo> buttons)
: wxPopupTransientWindow(parent, wxBORDER_NONE | wxPU_CONTAINS_CONTROLS)
{
this->SetPosition(pos);
this->SetSize(50 * buttons.size(), 50);
this->SetBackgroundColour(wxColour(90, 93, 121));
panel = new wxWindow(this, wxID_ANY);
sizer = new wxBoxSizer(wxHORIZONTAL);
// costruisci struttura
for (unsigned int i = 0; i < buttons.size(); i++)
{
wxButton* btn = new wxButton(this, buttons.at(i).id, buttons.at(i).label);
sizer->Add(btn, 1, wxEXPAND);
}
panel->SetSizer(sizer);
}
expandMenu::~expandMenu()
{
}
这是我用于自定义 wxButton 的实际创建弹出窗口的代码(它是临时的):
void ikeButton::rightClick(wxMouseEvent& evt) // CREA PANNELLO ESTENSIONE
{
if (flags & EXPANDABLE)
{
std::vector<expandMenuInfo> buttons;
buttons.push_back(expandMenuInfo(L"sin", 3001));
buttons.push_back(expandMenuInfo(L"cos", 3002));
buttons.push_back(expandMenuInfo(L"tan", 3003));
expandMenu* menu = new expandMenu(this, wxGetMousePosition(), buttons);
menu->Popup();
}
}
提前感谢您的帮助,因为我是这个框架的新手。
要在弹出窗口 window 中设置按钮布局,在 expandMenu 的构造函数中,我认为您只需要将 panel->SetSizer(sizer);
更改为
SetSizerAndFit(sizer);
Layout();
从 UI 的角度来看,我认为 split button might be a better way to implement the functionality you are describing. wxWidgets doesn't currently have such a control, but this post 展示了两种不同的创建方法。
我认为问题在于您为按钮的 parent 指定了 this
,即弹出窗口 window。我认为您希望他们的 parent 成为 面板 。
我正在创建一个 C++ wxWidgets 计算器应用程序。我正在实现三角函数,为了节省 space,我在一个按钮中重新组合了所有这些函数。如果您右键单击该按钮,则会创建一个弹出窗口,其中包含所有功能的按钮。我正在为此工作使用派生的 wxPopupTransientWindow class,问题是按钮显示不正确。
这是我的代码:
expandMenu.h
#include "wx/wx.h"
#include "wx/popupwin.h"
struct expandMenuInfo
{
const wxString& label;
wxWindowID id;
expandMenuInfo(const wxString& l, wxWindowID i)
: label{l}
, id{i}
{}
};
class expandMenu : public wxPopupTransientWindow
{
wxWindow* panel;
wxBoxSizer* sizer;
public:
expandMenu(wxWindow* parent, wxPoint pos, std::vector<expandMenuInfo> buttons);
~expandMenu();
};
expandMenu.cpp
#include "expandMenu.h"
// PANNELLO ESTENSIONE
expandMenu::expandMenu(wxWindow* parent, wxPoint pos, std::vector<expandMenuInfo> buttons)
: wxPopupTransientWindow(parent, wxBORDER_NONE | wxPU_CONTAINS_CONTROLS)
{
this->SetPosition(pos);
this->SetSize(50 * buttons.size(), 50);
this->SetBackgroundColour(wxColour(90, 93, 121));
panel = new wxWindow(this, wxID_ANY);
sizer = new wxBoxSizer(wxHORIZONTAL);
// costruisci struttura
for (unsigned int i = 0; i < buttons.size(); i++)
{
wxButton* btn = new wxButton(this, buttons.at(i).id, buttons.at(i).label);
sizer->Add(btn, 1, wxEXPAND);
}
panel->SetSizer(sizer);
}
expandMenu::~expandMenu()
{
}
这是我用于自定义 wxButton 的实际创建弹出窗口的代码(它是临时的):
void ikeButton::rightClick(wxMouseEvent& evt) // CREA PANNELLO ESTENSIONE
{
if (flags & EXPANDABLE)
{
std::vector<expandMenuInfo> buttons;
buttons.push_back(expandMenuInfo(L"sin", 3001));
buttons.push_back(expandMenuInfo(L"cos", 3002));
buttons.push_back(expandMenuInfo(L"tan", 3003));
expandMenu* menu = new expandMenu(this, wxGetMousePosition(), buttons);
menu->Popup();
}
}
提前感谢您的帮助,因为我是这个框架的新手。
要在弹出窗口 window 中设置按钮布局,在 expandMenu 的构造函数中,我认为您只需要将 panel->SetSizer(sizer);
更改为
SetSizerAndFit(sizer);
Layout();
从 UI 的角度来看,我认为 split button might be a better way to implement the functionality you are describing. wxWidgets doesn't currently have such a control, but this post 展示了两种不同的创建方法。
我认为问题在于您为按钮的 parent 指定了 this
,即弹出窗口 window。我认为您希望他们的 parent 成为 面板 。