word wrap with wxStaticText

639 views
Skip to first unread message

Anna Maria Picciau

unread,
Mar 3, 2005, 6:23:40 AM3/3/05
to wx-u...@lists.wxwidgets.org
Hi everybody!
I'm trying to create a label for a text which could be longer than the
label itself, in which case it should be wrapped at the end of the word.
I have almost succeded, but the height of my label remains the same, so
that the text is not displayed properly.
Maye someone of you knows which mistake I am making....

Anyway thanks in advance.
Anna

Here is the piece of source code:
//! creates the new widget and sets its description
wxStaticText* unitWidget = new wxStaticText(parent, -1,
parameter.getName().c_str(),
wxPoint(-1,-1),
wxSize(150, -1),
wxTE_MULTILINE|wxTE_WORDWRAP|wxST_NO_AUTORESIZE);
unitWidget->SetBackgroundColour(parent->GetBackgroundColour());

//! adds tooltip and sets alignment of the new widget
unitWidget->SetToolTip( parameter.getDescription().c_str() );
//! for esthetic's sake set a fixed width but allow the word wrapping
unitWidget->SetSize(-1, -1, 110, -1,wxSIZE_USE_EXISTING );
unitWidget->Fit();
unitWidget->Show();


std::list<CBaseComponent*> widgList;

Anna Maria Picciau

unread,
Mar 3, 2005, 10:39:48 AM3/3/05
to wx-u...@lists.wxwidgets.org
Unfortunately it doesn't work..... look at the picture,
the height remains the same, although the text is larger.
I cannot specify another height, because it is a parameter dynamically given by the user.


David Norris wrote:
On Thu, 03 Mar 2005 12:23:40 +0100, Anna Maria Picciau
<p...@iis.fraunhofer.de> wrote:
  
Hi everybody!
I'm trying to create a label for a text which could be longer than the
label itself, in which case it should be wrapped at the end of the word.
I have almost succeded, but the height of my label remains the same, so
that the text is not displayed properly.
Maye someone of you knows which mistake I am making....
    
I think wxStaticText wraps automatically, if you make it big enough.
This works for me:

   m_text = new wxStaticText(panel, -1, wxT("This text can wrap"),
      wxDefaultPosition, wxDefaultSize, wxST_NO_AUTORESIZE);
   m_text->SetSizeHints(100, 30, -1, -1, -1, -1);

May not be a good idea to hard-code a specific height (30 pixels in
that example). If your text control is in a sizer, just give it a
nonzero proportion and make it expandable with wxEXPAND.

Cheers,
--
David Norris
dano...@gmail.com

---------------------------------------------------------------------
To unsubscribe, e-mail: wx-users-u...@lists.wxwidgets.org
For additional commands, e-mail: wx-use...@lists.wxwidgets.org
  
Clipboard.png

David Norris

unread,
Mar 3, 2005, 10:03:32 AM3/3/05
to wx-u...@lists.wxwidgets.org
On Thu, 03 Mar 2005 12:23:40 +0100, Anna Maria Picciau
<p...@iis.fraunhofer.de> wrote:
> Hi everybody!
> I'm trying to create a label for a text which could be longer than the
> label itself, in which case it should be wrapped at the end of the word.
> I have almost succeded, but the height of my label remains the same, so
> that the text is not displayed properly.
> Maye someone of you knows which mistake I am making....

I think wxStaticText wraps automatically, if you make it big enough.

Anna Maria Picciau

unread,
Mar 3, 2005, 10:49:09 AM3/3/05
to wx-u...@lists.wxwidgets.org
I am trying to group components which are in the same panel, displaying
a border ontothe panel.
My class is derived from wxPanel and is thus the panel itself. Depending
on a parameter given from the user, I display the group border or not.
Now, I am trying to call a static function in order to introduce the
border (with wxStaticBox and wxStaticBoxSizer) but I cannot achieve what
I want.
I am using exstaicBox but what I would like to do is just display a
border on the panel. What could I do?
Thanks for any suggestion
Anna

here is my code:

void CGuiBuilder::s_setGroup(CIISPanel* panel, bool group)
{
if (group)
{

wxStaticBox* sbox = new wxStaticBox(panel, -1, panel->GetName(),
wxPoint(15, 15), wxSize(wxDefaultSize));
wxStaticBoxSizer* ssizer = new wxStaticBoxSizer(sbox, wxVERTICAL);
ssizer->Add(panel,1, wxGROW|wxALL);
// panel->SetSizer(ssizer);
panel->setInternLayout(ssizer);

panel->SetAutoLayout( TRUE );

ssizer->Fit( panel );
ssizer->SetSizeHints( panel);
}
}


David Norris

unread,
Mar 3, 2005, 10:56:24 AM3/3/05
to wx-u...@lists.wxwidgets.org
On Thu, 03 Mar 2005 16:39:48 +0100, Anna Maria Picciau
<p...@iis.fraunhofer.de> wrote:
> Unfortunately it doesn't work..... look at the picture,
> the height remains the same, although the text is larger.
> I cannot specify another height, because it is a parameter dynamically
> given by the user.

It seems to me that if you're letting the user specify the height of
the box, and the user decides to give a height that's too small for
two lines of text, then surely that's the user's problem? What exact
behavior are you trying to get?

--
David Norris
dano...@gmail.com

Anna Maria Picciau

unread,
Mar 10, 2005, 11:08:45 AM3/10/05
to wx-u...@lists.wxwidgets.org
Hello,

I am trying to create a dynamic Gui, by letting the user decide whcih widgets should be create and  which default values/range they have.
The problem at this point is, that  wxWidgets wants me to declare the event table statically.
Is there a way to dynamic bind a function(which specify th e caller) to a new created wxWidget?
Thanks for any help

Anna
Reply all
Reply to author
Forward
0 new messages