Project

General

Profile

Line breaks in message box

Added by B Sorensen over 12 years ago

Hi,

I have some message boxes, where localized strings are used, such as:

new WMessageBox(WString::tr("advanced.rebootcaption"),WString::tr("advanced.rebootwarning"), NoIcon, Ok | Cancel);

If I have a rather long description for one of those keys in the XML file, the messagebox will expand to the edge of the browser window before breaking the line into 2. Can I manually decide where to put those line breaks in the XML file? I've tried the usual "\n", etc., but couldn't make any of them work.

The entry in the XML file in this case could be:

This action will reboot the unit. Some loooooong warning inserted here. Click 'OK' to confirm.


Replies (3)

RE: Line breaks in message box - Added by Ulf Johnsson over 12 years ago

Try this:

Wt::WMessageBox *pMessageBox = // your messagebox...

Wt::WText *pTextWidget = pMessageBox->textWidget();

pTextWidget->setTextFormat(Wt::TextWordWrap);

That should work, but in my experience the wordwrap-functions do not work, and in some cases throws exceptions, but try it

Regards,

Ulf Johnsson

RE: Line breaks in message box - Added by B Sorensen over 12 years ago

It seems to work ok with the line break in a limited test setup, if I call the following on the text widget:

pTextWidget->setTextFormat(XHTMLText);

pTextWidget->setWordWrap(true);

...and then write the string in the XML translate file with "" entries where I need the breaks.

I'll try to include in the main project and see if it works ok.

Thanks.

RE: Line breaks in message box - Added by François Legendre about 9 years ago

I set the width of the box and I get it like a charm

auto mb = new Wt::WMessageBox(Wt::WString::tr("..."), Wt::WString::tr("..."), Wt::NoIcon, Wt::Ok) ;

mb->setWidth("50%") ;

mb->setModal(false) ;

mb->setStyleClass("...") ;

mb->show() ;

mb->buttonClicked().connect(std::bind([=] () { delete mb ; })) ;

    (1-3/3)