В прошлом посте говоря "Все вызовы теперь одинаковы" я несколько слукавил. Всё-таки есть в этом зоопарке версий некоторая несовместимость вызов которой просто так не унифицировать. Эти моменты вынесены в отдельный модуль 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 faint spiral galaxy NGC 6946, also called the "Fireworks Galaxy," has hosted ten recorded supernovae in the past century—more than any other galaxy of its size. Its dazzling history of stellar explosions illuminates clouds of gas and dust, revealing fresh bursts of star formation and the ongoing cycle of cosmic destruction and rebirth. ✨
#supernovae⚡#galaxies⚡#NGC6946
👉subscribe Universe Mysteries
🪐 In the galaxy NGC 6946, astronomers have identified a pair of medium-sized black holes locked in a close orbit, slowly spiraling toward each other. As they draw closer together, they send out ripples in space called gravitational waves—faint yet powerful signals that help scientists trace the invisible dance of these hidden giants across millions of light-years. ✨
#blackholes⚡#NGC6946⚡#gravitationalwaves⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
🪐 In the galaxy NGC 6946, astronomers captured the supernova SN 2017eaw, a brilliant explosion marking the death of a red supergiant star about 22 million light-years away. This supernova was so bright that for a while, it outshone all the other stars in its galaxy combined, scattering newly forged elements like oxygen and silicon into space to seed future generations of stars and planets. ✨
#supernovae⚡#NGC6946⚡#cosmicexplosions⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels