wxStaticText wrapping causes the text to disappear entirely
09:24 28 May 2026

I'm trying to make a very simple chat client as a proof of concept and for this i decided to use wxWidgets. I use Linux/GTK. Chat clients need to show messages properly, so when window is resized, the text needs to wrap properly if you need to resize the chat window.

class ClientFrame : public wxFrame
{
public:
    ClientFrame(const wxString &title, const wxPoint &pos, const wxSize &size);

    void OnSize(wxSizeEvent& ev);

    wxStaticText* text;
    wxSizer* sizer;
};

ClientFrame::ClientFrame(const wxString &title, const wxPoint &pos, const wxSize &size)
    : wxFrame(NULL, wxID_ANY, title, pos, size)
{
    Bind(wxEVT_SIZE, &ClientFrame::OnSize, this);
    
    text = new wxStaticText(this, wxID_ANY, "..... very very long text .................. AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");

    sizer = new wxBoxSizer(wxVERTICAL);
    sizer->Add(text, 1, wxEXPAND | wxALL, 5);
    sizer->SetMinSize(wxSize(720, 1080));

    SetSizer(sizer);
}

void ClientFrame::OnSize(wxSizeEvent& ev)
{
    text->Wrap(ev.GetSize().GetWidth());
}

This example should recreate my problem. When I make the window fullscreen or just make the window bigger, the text doesn't have to wrap and it should show up as normal. But here it just goes away. Also the text might sometimes escape the window.

c++ text wxwidgets word-wrap