В прошлом посте говоря "Все вызовы теперь одинаковы" я несколько слукавил. Всё-таки есть в этом зоопарке версий некоторая несовместимость вызов которой просто так не унифицировать. Эти моменты вынесены в отдельный модуль 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 Baltic Sea is home to some of the world’s best-preserved shipwrecks, thanks to low salt levels and cold water that prevent wood-eating organisms from thriving. These underwater time capsules reveal centuries-old trade and naval history almost untouched. ✨
#history⚡#shipwrecks⚡#archaeology
👉subscribe Interesting Planet
🌎 Sunken ships dot the floor of the Black Sea, preserved for centuries by its deep, oxygen-free waters. Archaeologists have found ancient Greek, Roman, and Ottoman vessels intact, with wooden hulls and cargo still recognizable. Over 60 shipwrecks have been mapped there using underwater robots since 2015. ✨
#ocean⚡#archaeology⚡#shipwrecks
👉subscribe Interesting Planet
👉more Channels
🌎 The disappearance of the USS Cyclops in 1918 remains one of history’s biggest maritime mysteries. This U.S. Navy ship vanished in the Bermuda Triangle with 306 crew and passengers, and no wreckage or trace has ever been found despite extensive searches. ✨
#history⚡#mystery⚡#shipwrecks
👉subscribe Interesting Planet
🌎 Deep beneath the Black Sea lies a vast expanse of water with almost no oxygen. This "dead zone" preserves ancient shipwrecks for thousands of years, preventing wood and even ropes from decaying. ✨
#shipwrecks⚡#preservation⚡#ocean
👉subscribe Interesting Planet
🌎 Beneath the Red Sea’s warm waters, the "Sha’ab Abu Nuhas" coral reef has caused more shipwrecks than almost any other spot, earning it the nickname “Ship Graveyard.” Strong currents and hidden shallows have claimed dozens of vessels, now home to vibrant marine life among the sunken ruins. ✨
#shipwrecks⚡#coralreef⚡#maritime
👉subscribe Interesting Planet