从你的评论中可以明显看出
代码128
字体尚未正确安装在您的系统上,因此正在恢复到
MS Shell Dlg 2
默认情况下。
要准确查看系统上Qt可用的字体,可以执行以下操作:
>>> fd = QtGui.QFontDatabase()
>>> len(fd.families())
209
>>> for f in sorted(fd.families()): print(f)
...
Adobe Courier
Adobe Helvetica
Adobe New Century Schoolbook
Adobe Times
Adobe Utopia
Arabic Newspaper
B&H Lucida
B&H LucidaBright
B&H LucidaTypewriter
Bitstream Charter
Bitstream Terminal
Bitstream Vera Sans
Bitstream Vera Sans Mono
Bitstream Vera Serif
C059
Cantarell
Code 128
Code 128 low
Code 2 of 5 interleaved
Code 3 de 9
Code Datamatrix
Code EAN13
Code PDF417
D050000L
...
代码128
字体没有出现在此列表中,它肯定没有正确安装。网上有很多这种字体的免费版本(例如。
Free Barcode Font
),因此我建议您尝试安装其中一些。
如果这些字体
还
不要出现在Qt的字体系列列表中,您可以尝试显式添加它们,如下所示:
>>> QtGui.QFontDatabase.addApplicationFont('C:\\MyFonts\\code128.ttf')
要检查新安装的字体是否有效,请使用
QFontInfo
>>> font = QtGui.QFont('Code 128')
>>> info = QtGui.QFontInfo(font)
>>> info.family()
'Code 128'
(注意:检查
font.family()
在这里是不够的,因为这只会返回以前的内容
请求
,而不是实际发现的)。