#16278 closed defect (fixed)

wxStaticText with absolute size wraps long texts on several lines even if the width is enough

Reported by: d_hadzhiev Owned by: PC
Priority: low Milestone:
Component: wxGTK Version: 3.0.0
Keywords: wxStaticText Cc:
Blocked By: Blocking:
Patch: no



I'm using wxStaticText in one of my projects. The problem is that when the text is long the rendered text is on several lines, regardless of the width and height of the control itself. The control has enough width to render the full text on
single line and even reducing the height didn't change the behaviour. I found a workaround by placing the wxStaticText control in an absolutely sized panel, but I think the text should be sized according to its own size. I'm providing a modified minimal example.

Deyan Hadzhiev

Attachments (1)

minimal.cpp download (7.4 KB) - added by d_hadzhiev 16 months ago.
Modified minimal example with two wxStaticTexts and a measuring coloured panel.

Download all attachments as: .zip

Change History (3)

Changed 16 months ago by d_hadzhiev

Modified minimal example with two wxStaticTexts and a measuring coloured panel.

comment:1 Changed 16 months ago by vadz

  • Priority changed from normal to low
  • Status changed from new to confirmed

I can confirm the bug. The simplest workaround is not to specify the height at all, as this diff:

  • samples/minimal/minimal.cpp

    diff --git a/samples/minimal/minimal.cpp b/samples/minimal/minimal.cpp
    index 64d5356..6fcbcbf 100644
    a b bool MyApp::OnInit() 
    172172    CreateStatusBar(2);
    173173    SetStatusText("Welcome to wxWidgets!");
    174174#endif // wxUSE_STATUSBAR
     176    wxPanel * panel = new wxPanel(this);
     178    wxString testString("The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog.");
     179    int testWidth = 760;
     181    wxPanel * measure = new wxPanel(panel, wxID_ANY, wxPoint(20, 40), wxSize(testWidth, 9));
     182    measure->SetBackgroundColour(wxColour(255, 0, 0));
     184    new wxStaticText(panel, wxID_ANY, testString, wxPoint(20, 50), wxSize(testWidth, 50));
     186    new wxStaticText(panel, wxID_ANY, testString, wxPoint(20, 100), wxSize(testWidth, -1));
     188    wxPanel * wrapper = new wxPanel(panel, wxID_ANY, wxPoint(20, 150), wxSize(testWidth, 22));
     189    wrapper->SetBackgroundColour(wxColour(255, 255, 0));
     190    new wxStaticText(wrapper, wxID_ANY, testString);

shows, not specifying the height is enough to make it work.

It is still a bug that using even a big enough height results in wrapping, of course, however.

comment:2 Changed 15 months ago by PC

  • Owner set to PC
  • Resolution set to fixed
  • Status changed from confirmed to closed

In 76602:

fix wxStaticText improperly wrapping text when initial size is fully specified, closes #16278

Note: See TracTickets for help on using tickets.