PyQt: new API with Python 2

前端 未结 3 587
终归单人心
终归单人心 2020-12-10 17:52

PyQt has two different API\'s: the old and the new. By default you get the old API with Python 2 and the new API with Python 3. Is it possible to enable the new PyQt API wit

3条回答
  •  南方客
    南方客 (楼主)
    2020-12-10 18:09

    From this reddit comment,

    import sip
    API_NAMES = ["QDate", "QDateTime", "QString", "QTextStream", "QTime", "QUrl", "QVariant"]
    API_VERSION = 2
    for name in API_NAMES:
        sip.setapi(name, API_VERSION)
    from PyQt4.QtCore import *
    from PyQt4.QtGui import *
    from PyQt4.QtSvg import *
    from PyQt4.QtCore import pyqtSignal as Signal
    from PyQt4.QtCore import pyqtSlot as Slot
    

    (...although I would recommend from PyQt4 import QtCore etc instead of import *)

提交回复
热议问题