wxSimplebook not showing loaded via XRC.

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
OmniBlade
In need of some credit
In need of some credit
Posts: 4
Joined: Tue Apr 13, 2021 9:49 am

wxSimplebook not showing loaded via XRC.

Post by OmniBlade »

I'm having issue getting panels loaded into a wxSimplebook to show up. The simplebook is being loaded from XRC using a block like this in the xrc file:

Code: Select all

<object class="sizeritem">
    <option>1</option>
    <flag>wxEXPAND</flag>
    <border>1</border>
    <object class="wxBoxSizer">
        <orient>wxHORIZONTAL</orient>
        <object class="sizeritem">
            <option>1</option>
            <flag>wxEXPAND | wxALL</flag>
            <border>0</border>
            <object class="wxSimplebook" name="m_myBook" />
            <size>-1,145</size>
        </object>
    </object>
</object>
I then add panels from the the main frames constructor using a pointer to the object as follows:

Code: Select all

m_myBook->AddPage(new wxPanel(m_myBook), "My Panel");
m_myBook->ChangeSelection(0);
However when I run the program, the panel doesn't show up. The panels I'm creating defined in the xrc file as well, I'm not actually creating blank wxPanel objects in the actual program.

The intention is to have panels which can be switched depending on user actions and selections elsewhere in the program which I believe using wxSimplebook would be the easiest way to manange.
User avatar
doublemax@work
Super wx Problem Solver
Super wx Problem Solver
Posts: 474
Joined: Wed Jul 29, 2020 6:06 pm
Location: NRW, Germany

Re: wxSimplebook not showing loaded via XRC.

Post by doublemax@work »

Does the panel look correctly when you don't use the wxSimplebook?

Code: Select all

m_myBook->AddPage(new wxPanel(m_myBook), "My Panel");
m_myBook->ChangeSelection(0);
Is this real code? Where is the part that loads the XRC and creates the controls?
OmniBlade
In need of some credit
In need of some credit
Posts: 4
Joined: Tue Apr 13, 2021 9:49 am

Re: wxSimplebook not showing loaded via XRC.

Post by OmniBlade »

The frame and the simple book is created as follows using a wxrc generated header.

Code: Select all

wxXmlResource::Get()->LoadObject(this,parent,wxT("MyFrame"), wxT("wxFrame"));
m_myBook = XRCCTRL(*this,"m_myBook",wxSimplebook);
The panels are also created from classes in the generated header.

If I generate the panels on their own they show up.
User avatar
doublemax@work
Super wx Problem Solver
Super wx Problem Solver
Posts: 474
Joined: Wed Jul 29, 2020 6:06 pm
Location: NRW, Germany

Re: wxSimplebook not showing loaded via XRC.

Post by doublemax@work »

Code: Select all

<size>-1,145</size>
What happens if you set an explicit width here instead of -1?
OmniBlade
In need of some credit
In need of some credit
Posts: 4
Joined: Tue Apr 13, 2021 9:49 am

Re: wxSimplebook not showing loaded via XRC.

Post by OmniBlade »

Still no joy I'm afraid.For reference, this is using a static 32bit wxWidgets build of 3.0.5 on windows.
User avatar
doublemax@work
Super wx Problem Solver
Super wx Problem Solver
Posts: 474
Joined: Wed Jul 29, 2020 6:06 pm
Location: NRW, Germany

Re: wxSimplebook not showing loaded via XRC.

Post by doublemax@work »

There are not many things that can go wrong here, but i've never used XRC.

Try this: Set an explicit size and a distinctive background color (e.g. red) to the wxSimplebook
If it's not visible, check its coordinates and parent. Maybe it's outside the window area or covered by something else
OmniBlade
In need of some credit
In need of some credit
Posts: 4
Joined: Tue Apr 13, 2021 9:49 am

Re: wxSimplebook not showing loaded via XRC.

Post by OmniBlade »

I've realised my mistake, I had the size specified outside the object tags.

This:

Code: Select all

<object class="wxSimplebook" name="m_myBook" />
<size>-1,145</size>
Where i should have had this:

Code: Select all

<object class="wxSimplebook" name="m_myBook">
    <size>-1,145</size>
</object>
With this change the controls show up as expected.
Post Reply