wxFrame starts with extremely small size. 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
apoorv569
Super wx Problem Solver
Super wx Problem Solver
Posts: 426
Joined: Tue Oct 20, 2020 3:35 pm

wxFrame starts with extremely small size.

Post by apoorv569 »

In my project I had 2 classes, MainFrame and Browser. The MainFrame was inheriting from wxFrame, and just defined the frame and nothing else just a couple of lines, that set the title, position, size and a object to Browser class which was inheriting from wxPanel and had all GUI widgets defined in it. But recently I merged the 2 into one class called MainFrame. After adjusting a couple of things needed to fix the merge process, I got it working, but I noticed for some reason, when I launch the app it starts extremely small, I can resize it, and everything seems to work fine no crash or anything. What could cause this size issue, here is a screenshot of when I launch the application,
Image

And here is the relevant code, where I set the set size for the frame,

Code: Select all

void MainFrame::LoadConfigFile()
{
    int height = 600, width = 800;

    Settings settings(m_ConfigFilepath, m_DatabaseFilepath);
    Serializer serialize(m_ConfigFilepath);

    wxString font_face = serialize.DeserializeDisplaySettings().font_face;
    int font_size = serialize.DeserializeDisplaySettings().font_size;

    serialize.DeserializeBrowserControls("autoplay", bAutoplay);
    serialize.DeserializeBrowserControls("loop", bLoop);
    serialize.DeserializeBrowserControls("muted", bMuted);

    height = serialize.DeserializeWinSize("Height", height);
    width = serialize.DeserializeWinSize("Width", width);

    settings.GetFontType().SetFaceName(font_face);
    settings.GetFontType().SetPointSize(font_size);

    this->SetFont(settings.GetFontType());
    this->SetSize(width, height);
    this->CenterOnScreen(wxBOTH);
    this->SetIcon(wxIcon("../assets/icons/icon-hive_24x24.png", wxICON_DEFAULT_TYPE, -1, -1));
}
I call this method in the first line of the constructor,

Code: Select all

MainFrame::MainFrame()
    : wxFrame(NULL, wxID_ANY, "SampleHive", wxDefaultPosition),
      m_ConfigFilepath("config.yaml"), m_DatabaseFilepath("sample.hive")
{
    LoadConfigFile();
.
.
.
}
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: wxFrame starts with extremely small size.

Post by PB »

Sorry, but the obvious question needs to be asked (aside GTK version you use): Are you sure the window size retrieved from config is what you expect it to be?

I do not use Linux but AFAIK, the window creation is deferred there but I think wxWidgets works around it. Still, I would try loading the config using CallAfter() instead of directly from the ctor. But it does seem silly.
apoorv569
Super wx Problem Solver
Super wx Problem Solver
Posts: 426
Joined: Tue Oct 20, 2020 3:35 pm

Re: wxFrame starts with extremely small size.

Post by apoorv569 »

PB wrote: Sorry, but the obvious question needs to be asked (aside GTK version you use):
Image
PB wrote: Are you sure the window size retrieved from config is what you expect it to be?
Yes, it does retrieve the correct size from the config file, I had print statements before and after fetching the values from config file, and it does indeed retrieve them.
PB wrote: I do not use Linux but AFAIK, the window creation is deferred there but I think wxWidgets works around it. Still, I would try loading the config using CallAfter() instead of directly from the ctor. But it does seem silly.
I see, It was working before though, when I had separate class for wxFrame and the wxPanel. I'll try CallAfter() and see if that helps.
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxFrame starts with extremely small size.

Post by doublemax »

Do you have a SetSizerAndFit() call or something similar later in the code?
Use the source, Luke!
apoorv569
Super wx Problem Solver
Super wx Problem Solver
Posts: 426
Joined: Tue Oct 20, 2020 3:35 pm

Re: wxFrame starts with extremely small size.

Post by apoorv569 »

doublemax wrote: Tue May 18, 2021 9:40 am Do you have a SetSizerAndFit() call or something similar later in the code?
I figured out the problem when you said this. I had this in the code,

Code: Select all

    this->SetSizer(m_MainSizer);
    m_MainSizer->Fit(this);
    m_MainSizer->SetSizeHints(this);
    m_MainSizer->Layout();
I changed it to,

Code: Select all

    this->SetSizer(m_MainSizer);
    this->Layout();
    this->Center(wxBOTH);
This fixed the problem. I think I forgot to change this as "this" was wxPanel previously.
Post Reply