我正在使用外部XRC方法通过wxFormBuilder实现我的用户界面。

我正在尝试实现以这种方式从wxStaticBoxSizer挂起的一组面板:

MainFrame::MainFrame(const wxString& title, const wxPoint& pos, const wxSize& size) {

    wxXmlResource::Get()->LoadFrame((wxFrame*)this,  (wxWindow*)NULL , wxT("MyFrame1"));

    wxStaticBoxSizer* almacenador = (wxStaticBoxSizer*)FindItem(XRCID("Contenedor"));

    if (!almacenador){
        cout << "Error cargando sizer!" << endl << flush;
    }

    wxXmlResource::Get()->LoadPanel( (wxWindow*)almacenador , wxT("MyPanel6"));
    wxXmlResource::Get()->LoadPanel( (wxWindow*)almacenador , wxT("MyPanel6"));
    wxXmlResource::Get()->LoadPanel( (wxWindow*)almacenador , wxT("MyPanel6"));

    SetTitle(title);
    SetIcon(wxICON(appicon));
    SetSize(size);
    SetPosition(pos);

    Show(true);
}


从“主要”功能加载资源的位置

wxXmlResource::Get()->Load("rc/resource2.xrc");


线。启动程序时,它可以正常工作,因为我在任何地方都看不到三个面板。

这是我的XRC文件:

主框架:

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<resource xmlns="http://www.wxwindows.org/wxxrc" version="2.3.0.1">
    <object class="wxFrame" name="MyFrame1">
        <style>wxDEFAULT_FRAME_STYLE|wxTAB_TRAVERSAL</style>
        <size>283,401</size>
        <title></title>
        <centered>1</centered>
        <aui_managed>0</aui_managed>
        <object class="wxPanel" name="m_panel1">
            <style>wxTAB_TRAVERSAL</style>
            <object class="wxBoxSizer">
                <orient>wxVERTICAL</orient>
                <object class="sizeritem">
                    <option>0</option>
                    <flag>wxEXPAND</flag>
                    <border>5</border>
                    <object class="wxBoxSizer">
                        <orient>wxHORIZONTAL</orient>
                        <object class="sizeritem">
                            <option>0</option>
                            <flag>wxALL|wxALIGN_BOTTOM</flag>
                            <border>5</border>
                            <object class="wxStaticText" name="m_label_Nombre1">
                                <label>Nombre</label>
                                <wrap>-1</wrap>
                            </object>
                        </object>
                        <object class="sizeritem">
                            <option>1</option>
                            <flag>wxEXPAND|wxTOP|wxRIGHT|wxLEFT</flag>
                            <border>5</border>
                            <object class="wxTextCtrl" name="m_text_Nombre">
                                <value></value>
                            </object>
                        </object>
                    </object>
                </object>
                <object class="sizeritem">
                    <option>0</option>
                    <flag>wxALIGN_TOP|wxEXPAND</flag>
                    <border>5</border>
                    <object class="wxBoxSizer">
                        <orient>wxHORIZONTAL</orient>
                        <object class="sizeritem">
                            <option>0</option>
                            <flag>wxALL|wxALIGN_BOTTOM</flag>
                            <border>5</border>
                            <object class="wxStaticText" name="m_label_Apellidos">
                                <label>Apellidos</label>
                                <wrap>-1</wrap>
                            </object>
                        </object>
                        <object class="sizeritem">
                            <option>1</option>
                            <flag>wxTOP|wxRIGHT|wxLEFT</flag>
                            <border>5</border>
                            <object class="wxTextCtrl" name="m_text_Apellidos">
                                <value></value>
                            </object>
                        </object>
                    </object>
                </object>
                <object class="sizeritem">
                    <option>0</option>
                    <flag>wxEXPAND</flag>
                    <border>5</border>
                    <object class="wxBoxSizer">
                        <orient>wxHORIZONTAL</orient>
                        <object class="sizeritem">
                            <option>0</option>
                            <flag>wxALL|wxALIGN_BOTTOM</flag>
                            <border>5</border>
                            <object class="wxStaticText" name="m_label_Edad">
                                <label>Edad</label>
                                <wrap>-1</wrap>
                            </object>
                        </object>
                        <object class="sizeritem">
                            <option>0</option>
                            <flag>wxALIGN_BOTTOM|wxALIGN_RIGHT|wxTOP|wxRIGHT|wxLEFT</flag>
                            <border>5</border>
                            <object class="wxSpinCtrl" name="m_spin_Edad">
                                <style>wxSP_ARROW_KEYS</style>
                                <value>0</value>
                                <min>0</min>
                                <max>10</max>
                            </object>
                        </object>
                    </object>
                </object>
                <object class="sizeritem">
                    <option>0</option>
                    <flag>wxEXPAND | wxALL</flag>
                    <border>5</border>
                    <object class="wxStaticLine" name="m_staticline1">
                        <style>wxLI_HORIZONTAL</style>
                    </object>
                </object>
                <object class="sizeritem">
                    <option>1</option>
                    <flag>wxEXPAND</flag>
                    <border>5</border>
                    <object class="wxBoxSizer">
                        <orient>wxHORIZONTAL</orient>
                        <object class="sizeritem">
                            <option>1</option>
                            <flag>wxALL|wxEXPAND</flag>
                            <border>5</border>
                            <object class="wxRadioBox" name="m_radioBox_Sexo">
                                <label>Sexo</label>
                                <selection>0</selection>
                                <content>
                                    <item>Hombre</item>
                                    <item>Mujer</item>
                                </content>
                                <dimension>1</dimension>
                            </object>
                        </object>
                        <object class="sizeritem">
                            <option>1</option>
                            <flag>wxEXPAND|wxALL</flag>
                            <border>5</border>
                            <object class="wxStaticBoxSizer">
                                <orient>wxVERTICAL</orient>
                                <label>Preferencias</label>
                                <object class="sizeritem">
                                    <option>0</option>
                                    <flag>wxALL</flag>
                                    <border>5</border>
                                    <object class="wxCheckBox" name="m_checkBox_Cocacola">
                                        <label>Cocacola</label>
                                        <checked>0</checked>
                                    </object>
                                </object>
                                <object class="sizeritem">
                                    <option>0</option>
                                    <flag>wxALL</flag>
                                    <border>5</border>
                                    <object class="wxCheckBox" name="m_checkBox_FantaNaranja">
                                        <label>Fanta naranja</label>
                                        <checked>0</checked>
                                    </object>
                                </object>
                                <object class="sizeritem">
                                    <option>0</option>
                                    <flag>wxALL</flag>
                                    <border>5</border>
                                    <object class="wxCheckBox" name="m_checkBox_FantaLimon">
                                        <label>Fanta Limon</label>
                                        <checked>0</checked>
                                    </object>
                                </object>
                            </object>
                        </object>
                    </object>
                </object>
                <object class="sizeritem">
                    <option>1</option>
                    <flag>wxEXPAND</flag>
                    <border>5</border>
                    <object class="wxStaticBoxSizer" name="Contenedor">
                        <orient>wxVERTICAL</orient>
                        <label>Contenedor</label>
                        <object class="sizeritem">
                            <option>0</option>
                            <flag>wxALL</flag>
                            <border>5</border>
                            <object class="wxButton" name="m_button4">
                                <label>MyButton</label>
                                <default>0</default>
                            </object>
                        </object>
                    </object>
                </object>
                <object class="sizeritem">
                    <option>0</option>
                    <flag>wxALIGN_BOTTOM</flag>
                    <border>5</border>
                    <object class="wxBoxSizer">
                        <orient>wxHORIZONTAL</orient>
                        <object class="sizeritem">
                            <option>0</option>
                            <flag>wxALL</flag>
                            <border>5</border>
                            <object class="wxButton" name="m_button_Guardar">
                                <label>Guardar</label>
                                <default>0</default>
                            </object>
                        </object>
                        <object class="sizeritem">
                            <option>0</option>
                            <flag>wxALL</flag>
                            <border>5</border>
                            <object class="wxButton" name="m_button_Limpiar">
                                <label>Limpiar</label>
                                <default>0</default>
                            </object>
                        </object>
                        <object class="sizeritem">
                            <option>0</option>
                            <flag>wxALL</flag>
                            <border>5</border>
                            <object class="wxButton" name="m_button_Salir">
                                <label>Salir</label>
                                <default>0</default>
                            </object>
                        </object>
                    </object>
                </object>
            </object>
        </object>
    </object>
</resource>


第二个(将对象重复作为数组):

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<resource xmlns="http://www.wxwindows.org/wxxrc" version="2.3.0.1">
    <object class="wxPanel" name="MyPanel6">
        <style>wxTAB_TRAVERSAL</style>
        <size>500,300</size>
        <object class="wxBoxSizer">
            <orient>wxVERTICAL</orient>
            <object class="sizeritem">
                <option>0</option>
                <flag>wxALL</flag>
                <border>5</border>
                <object class="wxButton" name="m_button5">
                    <label>FRAME2</label>
                    <default>0</default>
                </object>
            </object>
        </object>
    </object>
</resource>


如何在主XRC内制作XRC面板的阵列?
谢谢

最佳答案

首先,您的程序应该可怕地死掉,因为您是从wxStaticBoxSizer转换为wxWindow。我真的很想知道是什么让您有这样做的印象。

其次,没有在XRC中重复对象的规定,通常来说,如果您需要类似的东西,则在代码中创建3个不同的面板,并从相同的资源中加载每个面板,会更容易,更好。但是,如果您确实愿意,也可以使用object_ref XRC标记从其他地方引用现有对象。

关于c++ - 在其他xrc内部署xrc,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15882830/

10-16 23:29