В прошлом посте говоря "Все вызовы теперь одинаковы" я несколько слукавил. Всё-таки есть в этом зоопарке версий некоторая несовместимость вызов которой просто так не унифицировать. Эти моменты вынесены в отдельный модуль 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
🌎 Deep in the forests of Cameroon, the goliath frog boasts the title of world’s largest frog—growing up to 32 centimeters and weighing over 3 kilograms. This gentle giant even builds its own small ponds by moving stones, creating safe nurseries for its tadpoles. ✨
#amphibian⚡#wildlife⚡#adaptation
👉subscribe Interesting Planet
🌎 The wood frog (Rana sylvatica) survives winter by freezing solid, stopping its heartbeat and breathing for months. It produces special proteins and glucose that act as antifreeze, protecting its cells until it thaws and comes back to life in spring. ✨
#adaptation⚡#amphibian⚡#survival
👉subscribe Interesting Planet
👉more Channels
🌎 The wood frog survives Alaskan winters by freezing solid—its heart stops, and ice crystals form inside its body. Special proteins protect its cells until spring, when it thaws and hops away. Some populations can survive temperatures as low as -18°C. ✨
#adaptation⚡#amphibian⚡#freeze
👉subscribe Interesting Planet
🌎 The blue poison dart frog flashes vivid color as a warning—its skin holds toxins strong enough to deter most predators in the wild rainforest. Bright hues like these signal “stay away” in nature’s visual language. ✨
#amphibian⚡#rainforest⚡#color
👉subscribe Interesting Planet
🌎 The “ghost frog” of South Africa spends its life in icy, fast-flowing mountain streams. Its uniquely webbed toes and sticky pads let it grip slippery rocks, helping it thrive in waters too cold and rough for most frogs. ✨
#amphibian⚡#adaptation⚡#streams
👉subscribe Interesting Planet
🌎 The giant salamander of China is the world’s largest amphibian, reaching 1.8 meters in length. Its ancestors appeared about 170 million years ago, and it can live over 50 years in the wild. ✨
#salamander⚡#fossil⚡#amphibian
👉subscribe Interesting Planet
👉more Channels