如何在PyQt5中连续多次打印Unicode "u033F"?

How to print Unicode "u033F" multiple times continuously in PyQt5?

在我的代码中,QLabel_2 包含双上划线 (u"\u033F") 的 Unicode,QLabel_3 包含绘图框 (u"\2550") 的 Unicode。
问题:双上划线的Unicode在QLabel中没有连续打印,而我们在普通打印语句中使用这个Unicode,它连续打印(第11行),同时Unicode用于绘制框(在 QLabel_3 中),它工作正常。如何解决(连续打印双上划线)?

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
from PyQt5 import QtCore,QtGui,QtWidgets

class Layout_sample(QtWidgets.QWidget):
    def __init__(self):
        super(). __init__()
        self.setWindowTitle("Layout Sample")
        print((u"\u033f"+u"\u033f"+u"\u033f"+u"\u033f"+u"\u033f"+u"\u033f")      ##its work  file
        self.vbox = QtWidgets.QVBoxLayout()
        self.hbox1 = QtWidgets.QHBoxLayout()
        self.hbox2 = QtWidgets.QHBoxLayout()
        self.hbox3 = QtWidgets.QHBoxLayout()

        self.lbl1 = QtWidgets.QLabel("F3F3F3F3F3")
        self.lbl2 = QtWidgets.QLabel(u"\u033f"+u"\u033f"+u"\u033f"+u"\u033f"+u"\u033f"+u"\u033f")     
        self.lbl3 = QtWidgets.QLabel(u"\u2550"+u"\u2550"+u"\u2550"+u"\u2550")


        self.hbox1.addWidget(self.lbl1)
        self.hbox2.addWidget(self.lbl2)
        self.hbox3.addWidget(self.lbl3)

        self.vbox.addLayout(self.hbox1)
        self.vbox.addLayout(self.hbox2)
        self.vbox.addLayout(self.hbox3)
        self.vbox.addStretch()
        self.vbox.setSpacing(0)
        self.setLayout(self.vbox)

if __name__ =="__main__":
    app = QtWidgets.QApplication(sys.argv)
    mainwindow = Layout_sample()
    mainwindow.show()
    sys.exit(app.exec_())

033f 代码是 combining character。这意味着它需要另一个与之配对的字符才能正确显示。这类似于其他更标准的组合字符,例如“变音符号”(分音符),它通常与兼容的字母配对并且几乎从不单独显示。

现在,“问题”是Qt使用单个字符组合(包括组合字符)根据字体特征评估实际大小和绘图,这主要是指kerning/advance(这可能是来源你的问题):双上划线单独没有组合到任何东西(如果不是它们自己),所以它默认为组合字符的“总和”到“无字符”(默认为“一个字符”)。

一个可能的解决方法是将每个双行字符与 space:

配对
self.lbl2 = QtWidgets.QLabel(u'\u033f ' * 6)

但这不会很好地工作,原因有二:

  • “空”组合字符的宽度并不总是已知和透明的;
  • 如果字体不支持组合字符间距,你最终会得到类似 = = = = 的东西(或者不是 全黑 行);

所以,我怀疑是否存在针对您要实现的目标的实际且适当的解决方案(除了使用 u2550 字符),但如果您的目的是 draw 在指定数量的空白上双上划线 spaces,您可能更喜欢更简单的选项:使用 QPainter 并根据当前字体规格绘制线条。