python - 换行符和 PyQt

标签 python pyqt4 qtgui

使用 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/

相关文章:

Python 2.6 : proper usage of unittest. 测试套件

python - 我们如何在单击按钮时在 pyqt 中打开选项卡特定选项卡?

Qt:使用 Modkey(Shift、CTRL 等)检测双击

python - PyQt : How to stick a widget to the bottom edge of dialog

python - PyQt4:QtCore.QCoreApplication.instance().quit 和 self.close 之间的区别?

c++ - 使用 cmake 构建 Qt 4 项目时出错

python - 在discord.py中是否有类似于discord.js中的streamTime的东西?

python - 终止挂起的 redis pubsub.listen() 线程

python - 是否可以在 matplotlib hexbin 图中命名 x 轴和 y 轴?

macos - 如果从 finder 执行应用程序包但从命令行运行良好,则使用 python 构建的 OSX 应用程序会立即退出