В прошлом посте говоря "Все вызовы теперь одинаковы" я несколько слукавил. Всё-таки есть в этом зоопарке версий некоторая несовместимость вызов которой просто так не унифицировать. Эти моменты вынесены в отдельный модуль QtCompat (compatibility). Там не так много функций но они довольно полезны.
Этот модуль содержит унификаци модуля shiboken2, функций loadUi, translate и несколько переименованных функций классов или изменённую сигнатуру аргументов и возвращаемых значений. Это единственное исключение из правила когда вам потребуется где-то изменить свой код кроме импортов и этот код не похож на обычный код PySide2.
Например, в PyQt4 и PySide есть метод
QHeaderView.setResizeMode
Для PyQt5 и PySide2 они были благополучно переименованы в
QHeaderView.setSectionResizeMode
Чтобы применить этот метод следует использовать такой код
from Qt import QtCompath
header = self.horizontalHeader()
QtCompat.QHeaderView.setSectionResizeMode(header, QtWidgets.QHeaderView.Fixed)
Унификация загрузки UI файлов:
# PySide2
from PySide2.QtUiTools import QUiLoader
loader = QUiLoader()
widget = loader.load(ui_file)
# PyQt5
from PyQt5 import uic
widget = uic.loadUi(ui_file)
# Qt.py
from Qt import QtCompat
widget = QtCompat.loadUi(ui_file)
Хорошо что таких моментов не много и их легко запомнить.
Полный список можно посмотреть в таблице.
#qt#tricks
🌍 Canada’s Manitoulin Island is the largest freshwater island in the world. It’s so big that it contains more than 100 lakes, and some of those lakes have islands of their own. ✨
#islands⚡#freshwater⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography
👉more Channels
🌍 In Canada’s Hudson Bay lowlands, vast freshwater wetlands cover over 300,000 square kilometers. This area stores so much water it helps regulate the region’s climate and slow permafrost thaw. ✨
#wetlands⚡#freshwater⚡#climate⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography🌍
🌍 Just 0.001% of all water on Earth is found in rivers, lakes, and the atmosphere. The vast majority is locked away in ice sheets, glaciers, or underground where we rarely see it. ✨
#hydrology⚡#watercycle⚡#freshwater⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography🌍
🌍 Some freshwater wetlands form floating islands—mats of living plants thick enough to walk on. These islands create unique microhabitats and drift slowly across lakes or shallow wetlands. ✨
#wetlands⚡#freshwater⚡#ecology⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography
👉more Channels
🌍 The world's largest freshwater reserves are hidden underground as groundwater, not in lakes or rivers. These reserves are vital for drinking water and irrigation in many regions. ✨
#groundwater⚡#freshwater⚡#resources⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography🌍
🌍 Siberia's Lake Baikal holds more water than all the North American Great Lakes combined. It is the world’s deepest and oldest lake, home to unique species found nowhere else. ✨
#lake⚡#freshwater⚡#biodiversity⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography
👉more Channels
🌍 Lake Baikal in Russia holds about 20% of the world’s unfrozen freshwater. It’s also the oldest and deepest lake on the planet, reaching depths of over 1,640 meters. ✨
#Baikal⚡#freshwater⚡#depth⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography🌍