[SOLVED] Overlapping TextCtrls

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
Slyde
Earned some good credits
Earned some good credits
Posts: 136
Joined: Mon Apr 09, 2018 11:08 pm

[SOLVED] Overlapping TextCtrls

Post by Slyde »

I have a wxNoteBook that I add a page to that'll hold a wxPanel with two TextCtrls on it. But when I run it, the two TextCtrls are overlapping, one lying on top of the other. But as soon as I resize it even one pixel, the TextCtrls jump into place.

Code: Select all

{
    wxBoxSizer* mainSizer = new wxBoxSizer( wxVERTICAL);
    wxNotebook* notebook = new wxNotebook(this, wxID_ANY);
    mainSizer->Add( notebook, 1, wxEXPAND | wxALL, 5);


    wxPanel *panel1 = new wxPanel(notebook, wxID_ANY);
    wxBoxSizer *panel1Sizer = new wxBoxSizer(wxVERTICAL);
    panel1->SetSizer(panel1Sizer);

    wxBoxSizer *textCtrl1Sizer = new wxBoxSizer(wxHORIZONTAL);
    wxTextCtrl* textCtrl1 = new wxTextCtrl(panel1, wxID_ANY, "textCtrl1");
    textCtrl1Sizer->Add(textCtrl1, 1);
    panel1Sizer->Add(textCtrl1Sizer, 0, wxEXPAND | wxALL, 5);

    wxBoxSizer *textCtrl3Sizer = new wxBoxSizer(wxHORIZONTAL);
    wxTextCtrl* textCtrl3 = new wxTextCtrl(panel1, wxID_ANY, "textCtrl3");
    textCtrl3Sizer->Add(textCtrl3, 1);
    panel1Sizer->Add(textCtrl3Sizer, 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 5);

    notebook->AddPage(panel1, L"Tab 1");

    SetSizer(mainSizer);

    SetMinClientSize(wxSize(1000,550));

    mainSizer->Fit(this);
}
What am I missing?

Screenshot from 2021-09-25 01-05-52.png
Screenshot from 2021-09-25 01-05-52.png (7.59 KiB) Viewed 1029 times
Screenshot from 2021-09-25 01-06-14.png
Screenshot from 2021-09-25 01-06-14.png (9.22 KiB) Viewed 1029 times
Last edited by Slyde on Sat Sep 25, 2021 11:45 am, edited 1 time in total.
Linux Mint 21.3 | wxWidgets-3.2.4
Windows 10 | wxWidgets-3.2.4
CLion IDE
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4204
Joined: Sun Jan 03, 2010 5:45 pm

Re: Overlapping TextCtrls

Post by PB »

FWIW, the controls are displayed properly from start on Win10 with GIT master, when running it like this

Code: Select all

#include <wx/wx.h>
#include <wx/notebook.h>

class MyFrame : public wxFrame
{
public:
    MyFrame() : wxFrame(nullptr, wxID_ANY, "Test")
    {
        wxBoxSizer* mainSizer = new wxBoxSizer( wxVERTICAL);
        wxNotebook* notebook = new wxNotebook(this, wxID_ANY);
        mainSizer->Add( notebook, 1, wxEXPAND | wxALL, 5);


        wxPanel *panel1 = new wxPanel(notebook, wxID_ANY);
        wxBoxSizer *panel1Sizer = new wxBoxSizer(wxVERTICAL);
        panel1->SetSizer(panel1Sizer);

        wxBoxSizer *textCtrl1Sizer = new wxBoxSizer(wxHORIZONTAL);
        wxTextCtrl* textCtrl1 = new wxTextCtrl(panel1, wxID_ANY, "textCtrl1");
        textCtrl1Sizer->Add(textCtrl1, 1);
        panel1Sizer->Add(textCtrl1Sizer, 0, wxEXPAND | wxALL, 5);

        wxBoxSizer *textCtrl3Sizer = new wxBoxSizer(wxHORIZONTAL);
        wxTextCtrl* textCtrl3 = new wxTextCtrl(panel1, wxID_ANY, "textCtrl3");
        textCtrl3Sizer->Add(textCtrl3, 1);
        panel1Sizer->Add(textCtrl3Sizer, 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 5);

        notebook->AddPage(panel1, L"Tab 1");

        SetSizer(mainSizer);

        SetMinClientSize(wxSize(1000,550));

        mainSizer->Fit(this);
    }
};

class MyApp : public wxApp
{
public:
    bool OnInit() override
    {
        (new MyFrame)->Show();
        return true;
    }
}; wxIMPLEMENT_APP(MyApp);
The code looks OK to me, no extra calls like Layout() or even SendSizeEvent() should be needed. OTOH, trying if it helps probably would do no harm.
Slyde
Earned some good credits
Earned some good credits
Posts: 136
Joined: Mon Apr 09, 2018 11:08 pm

Re: Overlapping TextCtrls

Post by Slyde »

Thanks for the reply, PB. I actually got it to work just now by adding another boxSizer with a couple buttons in it.

Screenshot from 2021-09-25 06-38-03.png
Screenshot from 2021-09-25 06-38-03.png (14.06 KiB) Viewed 968 times
Linux Mint 21.3 | wxWidgets-3.2.4
Windows 10 | wxWidgets-3.2.4
CLion IDE
Post Reply