请告诉我如何替换此代码:
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))