使用 QtGui.QMessageBox 显示消息、警告和错误。
当与 html 标签一起使用时,QMessageBox 似乎不想使用“\n”换行符
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."
在QMessageBox中显示时全部显示为一长行。
提前致谢!
最佳答案
您看到的行为完全符合预期。这是 HTML 4 规范的一部分,除了在 PRE 标签内,空白字符序列应该始终折叠成一个空格。引用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.
因此,当您需要插入换行符时,请使用 <br>
明确地执行此操作标签。
附言:
这里还值得注意的是,Qt 的文本小部件仅支持一组有限的 HTML 标记、属性和 CSS 属性。有关详细信息,请参阅 Supported HTML Subset在 Qt 文档中。
关于python - 换行符和 PyQt,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20449898/