3

Using QtGui.QMessageBox to display the messages, warnings and errors.

It seems that QMessageBox doesn't want to work with "\n" new line character when used with html tags

message =  "<a href = http://www.google.com> GOOGLE</a> This a line number one.\n This a line number two. \n And this is a line number three."

is all being displayed as one long line when displayed within QMessageBox.

Thanks in advance!

alphanumeric
  • 17,967
  • 64
  • 244
  • 392
  • Please post your code where you call the message box. – Burhan Khalid Dec 08 '13 at 06:20
  • @sputnix, replace \n with
    – qurban Dec 08 '13 at 06:35
  • 1
    "doesn't want to work with `\n` new line character when used with html tags". Did you ever try to use a newline inside an HTML text? Because it's *always* ignored. If you have these kind of doubts you should read some HTML tutorial. – Bakuriu Dec 08 '13 at 07:15

1 Answers1

8

The behaviour you are seeing is entirely as expected. It is part of the HTML 4 spec that, other than inside PRE tags, sequences of whitepsace characters should always be collapsed to a single space. To quote the relevant part of the spec:

Note that a sequence of white spaces between words in the source document may result in an entirely different rendered inter-word spacing (except in the case of the PRE element). In particular, user agents should collapse input white space sequences when producing output inter-word space.

So, when you need to insert line-breaks, do it explicitly using the <br> tag.

PS:

It's also worth noting here that Qt's text widgets only support a limited set of HTML tags, attributes and CSS properties. For full details, see the Supported HTML Subset in the Qt docs.

ekhumoro
  • 115,249
  • 20
  • 229
  • 336