gpt4 book ai didi

c++ - 调整 wxDialogs 的大小,使所有文本都在对话框中

转载 作者:行者123 更新时间:2023-11-28 05:22:50 25 4
gpt4 key购买 nike

我的 wxWidgets 程序应该可以在桌面 PC 和 Windows 平板电脑上运行。两者均使用 Windows 10 Pro 64 位版本。我怎样才能使大小不断变化的文本无论在对话框中显示在何处?

这就是我现在做的:

TrackDialog::TrackDialog(wxWindow* parent,wxWindowID id,const wxPoint& pos,
const wxSize& size)
{
//(*Initialize(TrackDialog)
wxBoxSizer* BoxSizer4;
wxBoxSizer* BoxSizer5;
wxBoxSizer* BoxSizer2;
wxBoxSizer* BoxSizer1;
wxBoxSizer* BoxSizer3;
wxBoxSizer* pPanelSizer;

Create(parent, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxSTAY_ON_TOP|wxSUNKEN_BORDER, _T("wxID_ANY"));
Panel1 = new wxPanel(this, ID_PANEL1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, _T("ID_PANEL1"));
pPanelSizer = new wxBoxSizer(wxVERTICAL);
BoxSizer1 = new wxBoxSizer(wxHORIZONTAL);
StaticSelectText = new wxStaticText(Panel1, ID_STATICTEXT1, _("Select a *.xml file."), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT1"));
BoxSizer1->Add(StaticSelectText, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
pPanelSizer->Add(BoxSizer1, 0, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
BoxSizer2 = new wxBoxSizer(wxHORIZONTAL);
XmlFilePickerCtrl = new wxFilePickerCtrl(Panel1, ID_FILEPICKERCTRL1, _T("./resources/"), wxEmptyString, _T("*.xml"), wxDefaultPosition, wxDefaultSize, wxFLP_FILE_MUST_EXIST|wxFLP_OPEN|wxFLP_USE_TEXTCTRL, wxDefaultValidator, _T("ID_FILEPICKERCTRL1"));
BoxSizer2->Add(XmlFilePickerCtrl, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
pPanelSizer->Add(BoxSizer2, 0, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
BoxSizer3 = new wxBoxSizer(wxHORIZONTAL);
StaticNumberText = new wxStaticText(Panel1, ID_STATICTEXT2, _("Tracknumber \n"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT2"));
StaticNumberText->Disable();
wxFont StaticNumberTextFont(10,wxSWISS,wxFONTSTYLE_NORMAL,wxNORMAL,false,_T("Arial"),wxFONTENCODING_DEFAULT);
StaticNumberText->SetFont(StaticNumberTextFont);
BoxSizer3->Add(StaticNumberText, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
pPanelSizer->Add(BoxSizer3, 0, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
BoxSizer4 = new wxBoxSizer(wxHORIZONTAL);
ChoiceTrack = new wxChoice(Panel1, ID_CHOICE1, wxDefaultPosition, wxDefaultSize, 0, 0, 0, wxDefaultValidator, _T("ID_CHOICE1"));
ChoiceTrack->Disable();
BoxSizer4->Add(ChoiceTrack, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
pPanelSizer->Add(BoxSizer4, 0, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
BoxSizer5 = new wxBoxSizer(wxHORIZONTAL);
ButtonOk = new wxButton(Panel1, ID_BUTTON1, _("OK"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON1"));
BoxSizer5->Add(ButtonOk, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
pPanelSizer->Add(BoxSizer5, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
Panel1->SetSizer(pPanelSizer);
pPanelSizer->Fit(Panel1);
pPanelSizer->SetSizeHints(Panel1);
Center();

Connect(ID_FILEPICKERCTRL1,wxEVT_COMMAND_FILEPICKER_CHANGED,(wxObjectEventFunction)&TrackDialog::OnXmlFilePickerCtrlFileChanged);
Connect(ID_CHOICE1,wxEVT_COMMAND_CHOICE_SELECTED,(wxObjectEventFunction)&TrackDialog::OnChoiceTrackSelect1);
Connect(ID_BUTTON1,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&TrackDialog::OnButtonOkClick);
//*)
SetSize(DoGetBestClientSize());
Fit();
}

文本从“轨道编号”更改为以下选项之一:

void TrackDialog::setOutputAndChoice()
{
std::vector<wxString> storedTracks = m_xmlReader.getNamesOfTracks(m_path);
int numberOfTracks = storedTracks.size();
StaticNumberText->Enable();
wxString text;

// Make sure there are tracks stored in the file.
if(numberOfTracks > 0){
text = "There are ";
text += wxString::Format(wxT("%i"), numberOfTracks);
text += " tracks stored in the selected file. Select one."
"\nTrack 1 is the inner track.";
}
else{
text = "Opening file failed. Please chose another"
"file of the right format.";
}
StaticNumberText->SetLabel(text);
}

这就是它在台式机上的样子(在平板电脑上它看起来一样,感谢 SetSize(DoGetBestClientSize());)

example of Dialog

我该怎么做才能显示所有文本?在我调用 SetSizerAndFit() 之前,我已经尝试在构造函数中设置它,但是如果我想关闭它,我的程序就会崩溃...

感谢您的帮助。


编辑:我在 sizer 中为 StaticNumberText 和其中的文本放置了一个面板,现在我能够显示所有文本,尽管现在 StaticText 下方有一些讨厌的空间:

Nasty space

必须有更好的方法来正确布局带有更改文本的对话框...

最佳答案

Sizers 需要一个 Action 才能进入游戏。用户更改主(或对话框)窗口的大小绝对是一个 Action 。

您还可以触发要求对话框窗口适合其子项的操作。在 TrackDialog::setOutputAndChoice()

结束时调用 Fit()

关于c++ - 调整 wxDialogs 的大小,使所有文本都在对话框中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41096324/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com