В прошлом посте говоря "Все вызовы теперь одинаковы" я несколько слукавил. Всё-таки есть в этом зоопарке версий некоторая несовместимость вызов которой просто так не унифицировать. Эти моменты вынесены в отдельный модуль 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 magnetar Swift J1818.0−1607, discovered in 2020, has one of the fastest spins ever seen—rotating once every 1.36 seconds—and its magnetic field is up to a thousand trillion times stronger than a regular fridge magnet. Magnetars like Swift J1818.0−1607 are rare neutron stars with magnetic forces so intense they can reshape atoms and trigger sudden bursts of high-energy X-rays and gamma rays, making them some of the most extreme objects in the Milky Way. ✨
#magnetars⚡#neutronstars⚡#extrememagnetism⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels
🪐 The magnetar SGR 1900+14, located about 20,000 light-years away in the constellation Aquila, holds one of the strongest magnetic fields ever measured—over 100 trillion times stronger than Earth's. When its magnetic field twists and snaps, SGR 1900+14 unleashes enormous flares of X-rays and gamma rays that can briefly outshine every other X-ray source in our galaxy. ✨
#magnetars⚡#neutronstars⚡#extrememagnetism⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels
🪐 Deep in the constellation Vulpecula, the magnetar 1E 2259+586 unleashes magnetic fields so powerful—over 100 trillion times stronger than Earth's—that they can physically warp the star's crust. When these intense magnetic forces crack the surface, they release bursts of high-energy X-rays and gamma rays, briefly making the magnetar outshine every other X-ray source in its region of space. ✨
#magnetar⚡#neutronstar⚡#extrememagnetism⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels