Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

GUI Not Displaying All Components (C++)

I am following a tutorial to learn how to create simple GUIs with C++. (Video from the tutorial series I am using here(https://www.youtube.com/watch?v=_2FMt_0wVMM&list=PLFk1_lkqT8MbVOcwEppCPfjGOGhLvcf9G&index=4).

For this I am using Visual Studio 2022

Here is the code for the mainframe.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

#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.

Someone please help I’m learning this for a school project and I really want to get on with learning all this.

>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}
);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading