I want to move a wxStaticBitmap from frame to another Dialog, how to do?  [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.
lfjking
Earned some good credits
Earned some good credits
Posts: 101
Joined: Mon Nov 14, 2016 1:35 pm

I want to move a wxStaticBitmap from frame to another Dialog, how to do?

Postby lfjking » Sat Jul 14, 2018 7:11 am

I want to move a wxStaticBitmap from frame to another Dialog, how to do?

frame:

Code: Select all

///////////////////////////////////////////////////////////////////////////////
/// Class MyFrame.h
///////////////////////////////////////////////////////////////////////////////
#include "MyDialog.h"
class MyFrame : public wxFrame
{
   private:
   
   protected:
      wxScrolledWindow* m_scrolledWindow;
      wxStaticBitmap* m_bitmap;
      MyDialog*        m_dialog;
   public:
      
      MyFrame( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxEmptyString, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 500,300 ), long style = wxDEFAULT_FRAME_STYLE|wxTAB_TRAVERSAL );
      wxAuiManager m_mgr;
      
      ~MyFrame();
   
};
/// Class MyFrame.cpp
MyFrame::MyFrame( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : wxFrame( parent, id, title, pos, size, style )
{
   this->SetSizeHints( wxDefaultSize, wxDefaultSize );
   m_mgr.SetManagedWindow(this);
   m_mgr.SetFlags(wxAUI_MGR_DEFAULT);
   
   m_scrolledWindow = new wxScrolledWindow( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxHSCROLL|wxVSCROLL );
   m_scrolledWindow->SetScrollRate( 5, 5 );
   m_mgr.AddPane( m_scrolledWindow, wxAuiPaneInfo() .Center() .PinButton( true ).Dock().Resizable().FloatingSize( wxDefaultSize ) );
   
   wxGridSizer* gSizer;
   gSizer = new wxGridSizer( 0, 2, 0, 0 );
   
   m_bitmap = new wxStaticBitmap( m_scrolledWindow, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0 );
   gSizer->Add( m_bitmap, 0, wxALL, 5 );
   
   
   m_scrolledWindow->SetSizer( gSizer );
   m_scrolledWindow->Layout();
   gSizer->Fit( m_scrolledWindow );
   
   m_dialog = new MyDialog(this);
   
   m_mgr.Update();
   this->Centre( wxBOTH );
}

MyFrame::~MyFrame()
{
   m_mgr.UnInit();
   
}


and the Dialog:

Code: Select all

///////////////////////////////////////////////////////////////////////////////
/// Class MyDialog.h
///////////////////////////////////////////////////////////////////////////////
class MyDialog : public wxDialog
{
   private:
   
   protected:
   
   public:
      
      MyDialog( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxEmptyString, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxDEFAULT_DIALOG_STYLE ); wxAuiManager m_mgr;
      
      ~MyDialog();
   
};
/// Class MyDialog.cpp
MyDialog::MyDialog( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : wxDialog( parent, id, title, pos, size, style )
{
   this->SetSizeHints( wxDefaultSize, wxDefaultSize );
   m_mgr.SetManagedWindow(this);
   m_mgr.SetFlags(wxAUI_MGR_DEFAULT);
   
   
   m_mgr.Update();
   this->Centre( wxBOTH );
}

MyDialog::~MyDialog()
{
   m_mgr.UnInit();
   
}



now ,how can I put the m_bitmap ( wxStaticBitmap ) from the MyFrame to the MyDialog?

User avatar
doublemax
Moderator
Moderator
Posts: 12818
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: I want to move a wxStaticBitmap from frame to another Dialog, how to do?

Postby doublemax » Sat Jul 14, 2018 8:37 am

It's not totally clear to me what you want to do. If you just want to display the same bitmap in another window, i would suggest to just create a new wxStaticBitmap based on the same bitmap. Everything else would be unnecessarily complicated.
Use the source, Luke!

lfjking
Earned some good credits
Earned some good credits
Posts: 101
Joined: Mon Nov 14, 2016 1:35 pm

Re: I want to move a wxStaticBitmap from frame to another Dialog, how to do?  [SOLVED]

Postby lfjking » Sat Jul 14, 2018 8:56 am

doublemax wrote:It's not totally clear to me what you want to do. If you just want to display the same bitmap in another window, i would suggest to just create a new wxStaticBitmap based on the same bitmap. Everything else would be unnecessarily complicated.


sorry , I use the wrong fun setParent .
I can switch normally after using Reparent
:D
thanks!

lfjking
Earned some good credits
Earned some good credits
Posts: 101
Joined: Mon Nov 14, 2016 1:35 pm

Re: I want to move a wxStaticBitmap from frame to another Dialog, how to do?

Postby lfjking » Fri Nov 09, 2018 6:56 pm

doublemax wrote:It's not totally clear to me what you want to do. If you just want to display the same bitmap in another window, i would suggest to just create a new wxStaticBitmap based on the same bitmap. Everything else would be unnecessarily complicated.


the project same as this head page that I define
One of my classes is inherited from wxStaticBitmap, I call it myStBitmap.
I have to move him to work.
I can move him out. But when I tried to move him back, he warned:

Code: Select all

wxCHECK_RET( !m_containingSizer,
                     wxS("Adding a window already in a sizer, detach it first!") );


I don't know how to eliminate this warning.

I move the myStBitmap detach from the sizer first ,then Reparent the parent window. and move back too.

help me , please ! thanks.

lfjking
Earned some good credits
Earned some good credits
Posts: 101
Joined: Mon Nov 14, 2016 1:35 pm

Re: I want to move a wxStaticBitmap from frame to another Dialog, how to do?

Postby lfjking » Sat Nov 10, 2018 5:35 am

I check the code follow the breaking_point, I get the warried code:

Code: Select all

wxSizerItem* wxSizer::DoInsert( size_t index, wxSizerItem *item )
{
    m_children.Insert( index, item );

    if ( item->GetWindow() )
        item->GetWindow()->SetContainingSizer( this );

    if ( item->GetSizer() )
        item->GetSizer()->SetContainingWindow( m_containingWindow );

    return item;
}


Now I try to do like this:

Code: Select all

gSizer->Detach(myStBitmap);
if(m_is_away)
{
myStBitmap->Reparent(new_parent);
}
else{
myStBitmap->SetContainingSizer(NULL);//must set NULL, off warning !
myStBitmap->Reparent(this);
gSizer->Add(myStBitmap);
}




Then the warning was removed.

I don't know the SetContainingSizer what to do and why?
who can help me to understand it ?

Kvaz1r
Earned a small fee
Earned a small fee
Posts: 13
Joined: Tue Jun 07, 2016 1:07 pm

Re: I want to move a wxStaticBitmap from frame to another Dialog, how to do?

Postby Kvaz1r » Sat Nov 10, 2018 7:41 am

lfjking wrote:I don't know the SetContainingSizer what to do and why?

According to documentation:
This normally does not need to be called by user code.

It is called when a window is added to a sizer, and is used so the window can remove itself from the sizer when it is destroyed.

lfjking
Earned some good credits
Earned some good credits
Posts: 101
Joined: Mon Nov 14, 2016 1:35 pm

Re: I want to move a wxStaticBitmap from frame to another Dialog, how to do?

Postby lfjking » Sat Nov 10, 2018 8:22 am

Kvaz1r wrote:
lfjking wrote:I don't know the SetContainingSizer what to do and why?

According to documentation:
This normally does not need to be called by user code.

It is called when a window is added to a sizer, and is used so the window can remove itself from the sizer when it is destroyed.


I follow the debug one by one. I know why! haha @!~
look at here

Code: Select all

// a frame member
wxframe* m_frame1;
wxAuiManager m_mgr;

// another frame member
wxframe* m_frame2;
wxSizer* m_sizer;

// a panel;
wxPanel* m_panel;

//do :
 m_frame2->SetSizer(m_sizer);
 m_sizer->Add(m_panel);
 Layout();
 
 //put m_panel to  m_frame1
 m_sizer->Detach(m_panel );
 m_panel->Reparent( m_frame1);
 m_mgr.AddPane(m_panel );
 m_mgr.UpData();
 
  //put back the m_panel  to  m_frame2
/***the worry code:****/
   m_mgr.DetachPane( m_panel);
 m_panel->Reparent( m_frame2);
   m_sizer->Add(m_panel);                  //here  worried
   m_frame2->Layout();
 m_mgr.UpData();
/***the ok code:****/
   m_mgr.DetachPane( m_panel);
   m_mgr.UpData();            //m_panel still inside the m_mgr if not call  Updata() first.
 m_panel->Reparent( m_frame2);
   m_sizer->Add(m_panel);   
   m_frame2->Layout();



This is the problem that plagued me for many days.
Now it is finally settled.
I can sleep well.


Return to “C++ Development”

Who is online

Users browsing this forum: Artifact2238 and 27 guests