View Full Version : QMessageBox ignores nobr with rich text format

14th October 2008, 04:54
I'm porting a very simple application from Qt3.1 to Qt4. I read a line from a socket and then pop up a message window to display the text. The problem is that lines are automatically wrapped even if I surround the text with <nobr> tags. Here's a code fragment:

QString buffer=... // get the string text from our data source

buffer=buffer.simplified(); // chop and compress whitespace
QMessageBox qmb("QtAlert", "<html><font size=\"7\"><nobr>"+buffer+"</nobr></font></html>", QMessageBox::Information, QMessageBox::Ok|QMessageBox::Default, 0, 0);

// try to expand horizontally and not vertically
qmb.setSizePolicy(QSizePolicy(QSizePolicy::Ignored , QSizePolicy::Minimum));

// try to open our window on top
Qt::WindowFlags wflags=qmb.windowFlags();
qmb.setWindowFlags(wflags|Qt::WindowStaysOnTopHint );

Anything over about 12 characters gets wrapped in the middle of a word despite the <nobr> tag. For example, the string 'incontrovertibly' displays as:


I want the message box to expand horizontally to fit a line until it encounters an explicit <br />. What am I doing wrong?