В прошлом посте говоря "Все вызовы теперь одинаковы" я несколько слукавил. Всё-таки есть в этом зоопарке версий некоторая несовместимость вызов которой просто так не унифицировать. Эти моменты вынесены в отдельный модуль 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
🪐 Far in the constellation Carina, the peculiar galaxy ESO 137-001 speeds through the hot plasma of the Norma Cluster, leaving behind dramatic blue tendrils of stripped gas that trail for over 260,000 light-years. These glowing streams act as cosmic birthplaces, where stars are forming outside the galaxy itself—an ethereal wake marking where galactic material is torn away and reborn as new suns adrift in intergalactic space. ✨
#galaxies⚡#starformation⚡#Carina⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
🪐 The star RX J0806.3–4123, located about 1,200 light-years away in the constellation Carina, is an unusual "isolated neutron star" that emits almost only X-rays and spins once every 11 seconds. Unlike most neutron stars, which are powerful radio or gamma-ray sources, RX J0806.3–4123 glows quietly and steadily, making it a rare and mysterious member of the "Magnificent Seven," a group of neutron stars that reveal the hidden diversity of how dead stars can shine. ✨
#neutronstars⚡#carina⚡#xray⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels
🪐 The Bullet Cluster, found in the constellation Carina, provides some of the clearest real-world evidence for dark matter—a mysterious, invisible substance making up most of the universe’s mass. When two galaxy clusters crashed together, X-ray images showed that most of the visible matter stayed at the center, but gravity maps revealed most of the mass had moved ahead, proving something unseen—dark matter—was driving the collision's aftermath. ✨
#darkmatter⚡#galaxyclusters⚡#carina⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries