【发布时间】:2022-01-20 14:02:42
【问题描述】:
我在 PYQT5 中有一个字符串,我将其加载到包含小于和大于符号的 QLabel() 中。输出省略了符号和它们之间的所有内容。有没有办法按原样输出这个字符串?
from PyQt5.QtWidgets import *
import sys
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.setGeometry(100, 100, 400, 400)
self.centralWidget = QWidget()
self.setCentralWidget(self.centralWidget)
self.label = QLabel()
self.vLayout = QVBoxLayout()
self.vLayout.addWidget(self.label)
self.centralWidget.setLayout(self.vLayout)
myString = 'Supply Issue < 20 VDC when Speed > 100 MPH'
num = '10'
self.label.setText(f'<font color = "#E4551F">{num}:</font> {myString}')
app = QApplication(sys.argv)
myWin = MainWindow()
myWin.show()
app.exec()
'''
【问题讨论】:
-
您在哪个小部件上设置文本?我不认为 QListWidget 本身有文本。如果 HTML 是问题,您应该能够在插值字符串上使用 html.escape 将其解释为普通字符而不是 markdown
-
您是否使用自定义委托来显示格式化文本?另外,请提供minimal reproducible example。
-
对不起 - 我对问题出在哪里感到困惑。它在 QLabel 中——我已经解决了这个问题,这样它应该更容易回答。谢谢大家
标签: python html user-interface pyqt5 qlistwidget