В прошлом посте говоря "Все вызовы теперь одинаковы" я несколько слукавил. Всё-таки есть в этом зоопарке версий некоторая несовместимость вызов которой просто так не унифицировать. Эти моменты вынесены в отдельный модуль 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
🌎 The Steller’s sea cow, a giant marine mammal, was discovered in the Bering Sea in 1741 and went extinct just 27 years later due to overhunting. This species reached lengths up to 9 meters and fed on kelp, leaving no close living relatives today. ✨
#extinction⚡#megafauna⚡#ocean
👉subscribe Interesting Planet
🌎 Ice Age cave lions once roamed across Europe and Asia, hunting mammoths and bison in frigid steppe. Larger than today’s lions, these extinct predators are known from beautifully preserved cave paintings and even mummified cubs found in Siberian permafrost. ✨
#paleontology⚡#megafauna⚡#prehistory
👉subscribe Interesting Planet
🌎 The Gomphothere, an ancient cousin of elephants, once roamed the Americas with shovel-shaped lower jaws. These extinct giants sported four tusks instead of two, thriving for millions of years before vanishing at the end of the last Ice Age. ✨
#paleontology⚡#megafauna⚡#extinction
👉subscribe Interesting Planet
🌎 Australian megafauna like Diprotodon, the largest marsupial ever, disappeared about 46,000 years ago. These giant wombat relatives weighed up to 2,750 kilograms. The cause of their extinction is debated—some studies suggest climate shifts, while others blame human hunting. Diprotodon fossils have been found at over 100 sites across Australia. ✨
#extinctanimals⚡#megafauna⚡#paleontology
👉subscribe Interesting Planet
👉more Channels
🌎 The mystery of the Irish elk lies in its enormous antlers, which could span up to 3.5 meters. Despite the name, it lived across Eurasia and wasn’t truly an elk. Fossils suggest it vanished about 7,700 years ago, possibly due to climate change and habitat loss at the end of the last Ice Age. ✨
#extinct⚡#paleontology⚡#megafauna
👉subscribe Interesting Planet
👉more Channels