1

このコードを置き換える方法を教えてください:

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 API2Pythonと同等です。代わりにPython文字列を使用しているため、「NameError:グローバル名'QString'は定義されていません」と表示されます。ありがとうございました。

[解決済み]

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))
4

1 に答える 1

2

v2 api に切り替えるとQString、文字列関連の 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
于 2012-02-02T21:27:20.767 に答える