原文鏈接:https://blog.csdn.net/qw351363619/article/details/72301803
描述能力有限,不確定的翻譯會在旁邊注釋英文
更新時間:2017年05月12日
官網(wǎng)鏈接
不與 PyQt4 兼容
雖然實際上升級PyQt4寫的項目不是那么糟
不再對Python老版本提供支持(Python 2.6 之前)
不再實現(xiàn)PyQt4不推薦的API接口
PyQt5 不支持任何在PyQt4版本中標(biāo)記為不推薦或舍棄的Qt API(如果有就會當(dāng)Bug處理)
不再提供多版本API接口
PyQt4 支持多版本的API(如QString,QVariant等)
PyQt5 只支持最新的API版本(除QVariant外)
QVariant的改變是去掉了 QPyNullVariant (在QVariant的幫助文檔里也有顯示)
信號和插槽(Signals and Slots)機制更新
# 下面所列出來的調(diào)用方式不再支持
QObject.connect()
QObject.emit()
SIGNAL()
SLOT()
所有含有以SIGNAL()或SLOT()返回結(jié)果為參數(shù)的方法不再支持,轉(zhuǎn)而提供可調(diào)用方法(函數(shù))或已捆綁的信號(a bound signal)
風(fēng)格對比(代碼)
# PyQt5
combo = QtWidgets.QComboBox(self)
combo.activated.connect(self.onActivated)
# PyQt4
combo = QtWidgets.QComboBox(self)
self.connect(combo, QtCore.pyqtSignal('activated(QString)'), self.onActivated)
QObject.disconnect() 調(diào)用無參數(shù),作用斷掉所有信號和插槽的連接
TODO New-style Signals and Slots
Qt implements signals with an optional argument as two separate signals, one with the argument and one without it. PyQt4 exposed both of these allowing you to connect to each of them. However, when emitting the signal, you had to use the signal appropriate to the number of arguments being emitted.
PyQt5 exposes only the signal where all arguments are specified. However it allows any optional arguments to be omitted when emitting the signal.
Unlike PyQt4, PyQt5 supports the definition of properties, signals and slots in classes not sub-classed from QObject (i.e. in mixins).
新增 QtQml QtQuick 模塊并支持從QML創(chuàng)建Python對象
不再支持QtDeclarative, QtScript, QtScriptTools模塊
以上模塊被 QtQml 和 QtQuick 替換。
支持從QML創(chuàng)建Python對象
QtGui 模塊更新
QtGui模塊被拆分了為QtGui, QtPrintSupport 和QtWidgets三大模塊
from PyQt5 import QtGui, QtPrintSupport, QtWidgets
QtOpenGL 模塊更新
PyQt5的QtOpenGL模塊只提供QGLContext QGLFormat 和 QGLWidget類
QtWebKit 模塊更新
PyQt4的QtWebKit在PyQt5中分成了QtWebKit和QtWebKitWidgets模塊
擴展性增強
不再支持pyqtconfig模塊
The PyQt5 Extension API
PyQt5 支持第三方包直接基于PyQt5開發(fā)(如QScintilla)
dbus.mainloop.qt 模塊更名
#dbus.mainloop.qt
dbus.mainloop.pyqt5 # 相同功能只更名
QDataStream 明顯數(shù)值的參數(shù)以數(shù)值處理和返回
readUint8(); readInt8(); writeUInt8(); writeInt8() 方法在PyQt5中以數(shù)值類型寫入和返回(PyQt4中是以數(shù)值文本)
QFileDialog 文件操作接口更新
| PyQt5 | PyQt4 | 備注 |
|---|---|---|
| getOpenFileName() | getOpenFileNameAndFilter() | |
| getOpenFileNames() | getOpenFileNamesAndFilter() | |
| getSaveFileNameAndFilter() | getSaveFileName() |
PyQt5 舍棄了 PyQt4 同名的方法
QMatrix 方法不再支持
PyQt5 中已經(jīng)不再支持 PyQt4種不推薦方法 QMatrix
PyQt5 中可以考慮使用 QPropertyAnimation
QGraphicsItemAnimation 方法不再支持
PyQt5 中已經(jīng)不再支持 PyQt4種不推薦方法 QGraphicsItemAnimation
PyQt5 中可以考慮使用 QTransform
QPyTextObject 被舍棄
PyQt4 implements the QPyTextObject as a workaround for the inability to define a Python class that is sub-classed from more than one Qt class. PyQt5 does support the ability to define a Python class that is sub-classed from more than one Qt class so long as all but one of the Qt classes are interfaces, i.e. they have been declared in C++ as such using Q_DECLARE_INTERFACE. Therefore QPyTextObject is not implemented in PyQt5.
QSet 在PyQt5中完全用 集合 形式實現(xiàn)
pyuic5不再支持–pyqt3-wrapper參數(shù)
pyuic5 does not support the –pyqt3-wrapper flag of pyuic4.
pyrcc5 不再支持 -py2 或-py3參數(shù)
pyrcc5 does not support the -py2 and -py3 flags of pyrcc4. The output of pyrcc5 is compatible with all versions of Python starting with Python v2.6.
PyQt5 優(yōu)化 合作性多重繼承 (Cooperative Multi-inheritance)的初始化方式
# PyQt5 調(diào)用父類的`__init__`方法.
def __init(self, **kwargs):
super().__init__(**kwargs)
PyQt5 自動釋放GIL,而不是PyQt4的強制釋放
PyQt5 退出時自動調(diào)用sip.setdestroyonexit()以禁用自動析構(gòu)
Python解釋器退出PyQt4應(yīng)用程序時會默認(rèn)調(diào)用C++析構(gòu)器處理所有它擁有的線程(這通常是以隨機的順序,因此可能會導(dǎo)致解析器崩潰),通過調(diào)用 sip.setdestroyonexit() 函數(shù)可以禁用。
PyQt5 總會自動調(diào)用 sip.setdestroyonexit() 函數(shù).