我在笔记本旁边实施控件时遇到布局问题。
问题是,笔记本和它旁边的控件按预期正确对齐,但是笔记本中窗口上的控件彼此重叠,就好像没有使用大小调整器一样。
我感谢任何类型的输入如何解决这个问题。
编辑:提供示例代码来演示问题
头文件test.h:
class mainwindow : public wxFrame{
public:
mainwindow(const wxString &title);
wxWindow *notebookwindow[2];
wxTextCtrl *onnotebook[2];
wxNotebook *notebook;
wxTextCtrl *onmain[2];
wxBoxSizer *box[4];
};
class myapp : public wxApp {
public:
virtual bool OnInit();
};
测试.cpp
// program test
#include <iostream>
#include <stdlib.h>
#include <string>
#include <map>
#include <typeinfo>
#include <fstream>
#include <vector>
#include <wx/wx.h>
#include <wx/textctrl.h>
#include <wx/notebook.h>
#include <wx/stattext.h>
#include <wx/sizer.h>
#include "test.h"
mainwindow :: mainwindow (const wxString & title)
: wxFrame(NULL, wxID_ANY, title, wxDefaultPosition, wxSize(1000, 800)){
notebook = new wxNotebook(this, wxID_ANY, wxDefaultPosition, wxSize(200, 200));
notebookwindow[0] = new wxWindow(notebook, wxID_ANY);
notebookwindow[1] = new wxWindow(notebook, wxID_ANY);
notebook->AddPage(notebookwindow[0], wxT("This"));
notebook->AddPage(notebookwindow[1], wxT("That"));
onmain[0] = new wxTextCtrl(this, wxID_ANY, wxT("on main 1"));
onmain[1] = new wxTextCtrl(this, wxID_ANY, wxT("on main 2"));
onnotebook[0] = new wxTextCtrl(notebookwindow[0], wxID_ANY, wxT("on notebook 1"));
onnotebook[1] = new wxTextCtrl(notebookwindow[0], wxID_ANY, wxT("on notebook 2"));
box[0] = new wxBoxSizer(wxVERTICAL);
box[1] = new wxBoxSizer(wxVERTICAL);
box[2] = new wxBoxSizer(wxHORIZONTAL);
box[0]->Add(onmain[0]);
box[0]->Add(onmain[1]);
box[1]->Add(onnotebook[0]);
box[1]->Add(onnotebook[1]);
box[2]->Add(box[0]);
box[2]->Add(notebook);
notebookwindow[0]->SetSizer(box[1]);
this->SetSizer(box[2]);
}
bool myapp::OnInit(){
mainwindow *mainfr = new mainwindow( wxT("test"));
mainfr->Show(true);
return true;
}
IMPLEMENT_APP(myapp);
和makefile
main=test.o
flags=-std=c++11 -g
folders=tables sources
gui=`wx-config --cxxflags --libs`
all: $(addprefix doto/,$(main))
$(CXX) $(flags) $^ $(gui) -o test.exe
doto/%.o:%.cpp %.h
$(CXX) $(flags) $< $(gui) -c -o doto/$(notdir $(<:.cpp=.o))
.PHONY:clean
clean:
rm doto/*.o *.exe