Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyQt: new API with Python 2

Tags:

python

pyqt

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 with Python 2? How?

like image 607
Johan Råde Avatar asked Jun 04 '11 17:06

Johan Råde


1 Answers

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

like image 146
dbr Avatar answered Sep 22 '22 13:09

dbr