Search code examples
c++wxwidgets

Only last wxStaticBitmap is showing


The same image is meant to be shown in different locations but only the second one is shown, why?

void AppFrame::OnButtonClicked(wxCommandEvent& evt) {

    Tiles* knots = new Tiles(panel, 1);
    string tile = knots->firstTile();
    ImagePanel* drawPane = new ImagePanel(panel, tile, wxBITMAP_TYPE_PNG);

    wxStaticBitmap* image1 = new wxStaticBitmap(panel, wxID_ANY, drawPane->getImage(),wxPoint(Background::defaultStartX, Background::defaultStartY), wxSize(100, 100));
  
    wxStaticBitmap* image2 = new wxStaticBitmap(panel, wxID_ANY, drawPane->getImage(),wxPoint(Background::defaultStartX+100, Background::defaultStartY), wxSize(100, 100));

}

Solution

  • You don't position your ImagePanel and depending on its size it can overlap the first bitmap. Generally speaking, using hard-coded position in pixels is strongly discouraged, you should let the controls use their natural size and position them using sizers as already mentioned in a comment.