Update sizer after changing label of a wxStaticText

21 views
Skip to first unread message

schm...@gmx.de

unread,
Feb 14, 2024, 2:15:23 AMFeb 14
to wx-u...@googlegroups.com
Hi,

I have a wxStaticText which Label can change at runtime. After this, the
sizers aren't updated. After a resize of the window, or minimising and
getting the window back, everything is fine.

I tested it with wxWidgets 3.2.4 and Windows 10. But it happens with
older wx versions too.

For demonstrating the problem, I've the following code which can be
copied in the minimal sample:


auto sizer = new wxBoxSizer(wxHORIZONTAL);

label = new wxStaticText(this, wxID_ANY, "test");

sizer->Add(label, 0, wxGROW);

auto input = new wxTextCtrl(this, wxID_ANY, "Init String",
wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER | wxTE_RICH2);

sizer->Add(input, 0, wxGROW);

input->Bind(wxEVT_TEXT_ENTER, [this](wxCommandEvent& evt)
{
label->SetLabel(evt.GetString());
Update();
Refresh();

});

SetSizerAndFit(sizer);


It's just for demonstrating. When you enter a text, which is longer than
the old text in the text control, the label moves behind the textCtrl.

But, even when only resizing the window in vertical direction it
repaints the window and everything is fine.


Is there an other way to force a refresh of the window beside Update()
and Refresh()?

Best regards

Stefan

Gunter Königsmann

unread,
Feb 14, 2024, 3:03:05 AMFeb 14
to wx-u...@googlegroups.com
Layout();

Igor Korot

unread,
Feb 14, 2024, 3:05:21 AMFeb 14
to wx-u...@googlegroups.com
Hi,


On Wed, Feb 14, 2024, 1:15 AM schmensch via wx-users <wx-u...@googlegroups.com> wrote:
Hi,

I have a wxStaticText which Label can change at runtime. After this, the
sizers aren't updated. After a resize of the window, or minimising and
getting the window back, everything is fine.

You need to call Layout() on the window after changing the text.

Update() and Refresh() have no business there - it is to repaint the window.

Thank you.


I tested it with wxWidgets 3.2.4 and Windows 10. But it happens with
older wx versions too.

For demonstrating the problem, I've the following code which can be
copied in the minimal sample:


auto sizer = new wxBoxSizer(wxHORIZONTAL);

label = new wxStaticText(this, wxID_ANY, "test");

sizer->Add(label, 0, wxGROW);

auto input = new wxTextCtrl(this, wxID_ANY, "Init String",
wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER | wxTE_RICH2);

sizer->Add(input, 0, wxGROW);

input->Bind(wxEVT_TEXT_ENTER, [this](wxCommandEvent& evt)
      {
          label->SetLabel(evt.GetString());
          Update();
          Refresh();

      });

SetSizerAndFit(sizer);


It's just for demonstrating. When you enter a text, which is longer than
the old text in the text control, the label moves behind the textCtrl.

But, even when only resizing the window in vertical direction it
repaints the window and everything is fine.


Is there an other way to force a refresh of the window beside Update()
and Refresh()?

Best regards

Stefan

--
Please read https://www.wxwidgets.org/support/mlhowto.htm before posting.
---
You received this message because you are subscribed to the Google Groups "wx-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wx-users+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/wx-users/792d0cfb-f7a8-4430-b422-105c591434ee%40gmx.de.

Stefan Kruse

unread,
Feb 14, 2024, 3:43:07 AMFeb 14
to wx-u...@googlegroups.com
Great, thank you!

Stefan Kruse

unread,
Feb 14, 2024, 6:05:03 AMFeb 14
to wx-u...@googlegroups.com
Sorry, but I've to come back to my question.

Ist there any trick when the window is part of a wxAuiNotebook?

Layout() on the toplevel frame or on the concerned pane has no effect.

I also tried to update the wxAuiManager with no effect.

Thank you in advance,

Stefan

Igor Korot

unread,
Feb 14, 2024, 8:45:00 AMFeb 14
to wx-u...@googlegroups.com
Hi,


On Wed, Feb 14, 2024, 5:05 AM 'Stefan Kruse' via wx-users <wx-u...@googlegroups.com> wrote:
Sorry, but I've to come back to my question.

Ist there any trick when the window is part of a wxAuiNotebook?

Layout() on the toplevel frame or on the concerned pane has no effect.

Try calling Layout() on the topmost sizer.

Thank you.

Reply all
Reply to author
Forward
0 new messages