c++user-interfacewxwidgets

GUI Not Displaying All Components (C++)


I am using Visual Studio 2022

Here is the code for the mainframe.

#include "MainFrame.h"
#include <wx/wx.h>

MainFrame::MainFrame(const wxString& title) : wxFrame(nullptr, wxID_ANY, title) {
    wxPanel* panel = new wxPanel(this);

    wxButton* button = new wxButton(this, wxID_ANY, "Button", wxPoint(150, 50), wxSize(100, 35));

    wxCheckBox* checkBox = new wxCheckBox(panel, wxID_ANY, "CheckBox", wxPoint(550, 55));

    wxStaticText* staticText = new wxStaticText(panel, wxID_ANY, "Static Text - NOT editable", wxPoint(120, 150));
}

The code runs 100% fine, however when my GUI pops up when I run on debug, the GUI only displays the button, but not the text or the checkbox.

No checkbox or static text to be seen.


Solution

  • You need to make the panel bigger in order for the controls you place in it to be seen. You currently use mxDefaultSize, which is pretty small, as can be seen in the top left corner of your picture.

    The constructor you use is:

    wxPanel::wxPanel(
        wxWindow* parent,
        wxWindowID id = wxID_ANY,
        const wxPoint& pos = wxDefaultPosition,
        const wxSize& size = wxDefaultSize,       // <- set this to something bigger
        long style = wxTAB_TRAVERSAL,
        const wxString& name = wxPanelNameStr 
    )
    

    Example:

    wxPanel* panel = new wxPanel(
        this,
        wxID_ANY,
        wxDefaultPosition,
        {1000, 1000}
    );