2 Panels with different sizers Topic is solved

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
Tulliogs
In need of some credit
In need of some credit
Posts: 7
Joined: Wed Jun 09, 2021 12:08 pm

2 Panels with different sizers

Post by Tulliogs »

Hi,

I made an application to visualise the stream of my camera. When the application is running, the window display an image (and wxImagePanel) as a background( m_Background in my code). When the user want to displaythe video on the window, m_renderWindow in displayed front of the background. The problem is that I don't know how to define properly the sizers in order to have what I what.

My actual code is :

Code: Select all

m_background = new wxImagePanel(this, wxT("Logo.png"), wxBITMAP_TYPE_PNG);
    wxBoxSizer* sizerBackground = new wxBoxSizer(wxHORIZONTAL);
    sizerBackground->Add(m_background, 1, wxSHAPED | wxALIGN_CENTER);

    m_renderWindow = new wxPanel(this, wxID_ANY);
    wxBoxSizer* sizerStream = new wxBoxSizer(wxHORIZONTAL);
    sizerStream->Add(m_renderWindow, 1 , wxEXPAND);
    sizerBackground->Add(sizerStream);
    this->SetSizer(sizerBackground);
With this code, the image background have a good sizer and is properly rendered but the video is not displayed. If I change the 2 last lines by :

Code: Select all

    sizerStream->Add(sizerBackground);
    this->SetSizer(sizerStream);
The image background is not displayed but the video is properly displayed.

With the first configuration I have the image below :

Image

Where the red rectangle is my m_background and when I ask to display the video, nothing append.

With the second configuration I have :

Image

Where the background is not displayed, and when I ask to display the video I have the video rendering like in the picture below :

Image

But I want the first image when I start the application and the third one when I ask to display the video.
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: 2 Panels with different sizers

Post by doublemax »

Put both panels into so sizer, so that normally they would be displayed next to each other.
Then just Hide() the one you don't want to be visible and Show() the other one.

Another option would be to make the video panel a child of the image panel, so that it lies over it. Then Show() or Hide() just the video panel.
Use the source, Luke!
Tulliogs
In need of some credit
In need of some credit
Posts: 7
Joined: Wed Jun 09, 2021 12:08 pm

Re: 2 Panels with different sizers

Post by Tulliogs »

Thanks a lot, I do it like below :

Code: Select all

m_background = new wxImagePanel(this, wxT("Logo.png"), wxBITMAP_TYPE_PNG);
m_sizerBackground = new wxBoxSizer(wxHORIZONTAL);
m_sizerBackground->Add((*ptrstats).m_background, 1, wxSHAPED | wxALIGN_CENTER);
m_renderWindow = new wxPanel(this, wxID_ANY);
m_sizerBackground->Add((*ptrstats).m_renderWindow, 1 , wxEXPAND);
m_renderWindow->Hide();
this->SetSizer((*ptrstats).m_sizerBackground);
Layout();
When I decide to display the video, I do :

Code: Select all

m_background->Hide();
m_renderWindow->Show();
m_sizerBackground->Layout();
Post Reply