gpt4 book ai didi

python - PyQt - 如何用 sip API 2 替换 QString

转载 作者:行者123 更新时间:2023-12-01 06:03:41 25 4
gpt4 key购买 nike

请告诉我如何替换此代码:

import sip
sip.setapi("QString", 2)
...

text = QString.fromLatin1("<p>Character: <span style=\"font-size: 16pt; font-family: %1\">").arg(self.displayFont.family()) + \
QChar(key) + \
QString.fromLatin1("</span><p>Value: 0x") + \
QString.number(key, 16)

if QChar(self.lastKey).category() != QChar.NoCategory:
self.characterSelected.emit(QString(QChar(self.lastKey)))

与 sip API 2 Python 等效。它说“NameError:全局名称'QString'未定义”,因为我使用Python字符串。谢谢。

[已解决]

text = ('<p>Character: <span style="font-size: 16pt; font-family: %s">%s</span>
<p>Value: %#x' % (self.displayFont.family(), unichr(key), key))

if unicodedata.category(unichr(self.lastKey)) != 'Cn':
self.characterSelected.emit(unichr(self.lastKey))

最佳答案

切换到 QString 的 v2 api 会删除与字符串相关的 Qt 类,以便可以在任何地方使用 python 字符串。

因此,“sip API 2 Python 等效项”只是普通的 python 字符串处理:

>>> text = ('<p>Character: <span style="font-size: 16pt; '
... 'font-family: %s">%s</span><p>Value: %#x' %
... (font.family(), unichr(key), key))
>>>
>>> print text
<p>Character: <span style="font-size: 16pt; font-family: Sans Serif">A</span><p>Value: 0x41

关于python - PyQt - 如何用 sip API 2 替换 QString,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9108060/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com