В прошлом посте говоря "Все вызовы теперь одинаковы" я несколько слукавил. Всё-таки есть в этом зоопарке версий некоторая несовместимость вызов которой просто так не унифицировать. Эти моменты вынесены в отдельный модуль 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
🪐 Deep in the Milky Way, the star J0247-25B is a true cosmic oddball—it’s a rare "pre-helium white dwarf," meaning it’s caught in the act of shedding its outer layers before becoming a typical white dwarf star. This unusual star is much hotter than normal for its size, giving scientists a unique chance to watch stellar evolution unfold before their eyes and providing clues about how stars change shape and temperature toward the end of their lives. ✨
#unusualstars⚡#milkyway⚡#white⚡#dwarfs⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels
🪐 One of the most unusual stars known is SDSS J122859.93+104032.9, a "carbon-rich white dwarf" about 1,000 light-years from Earth. Unlike typical white dwarfs—stellar remnants made mostly of hydrogen and helium—this star's atmosphere is packed with carbon, giving it a faint, bluish glow and defying expectations about how dying stars shed their outer layers. ✨
#unusualstars⚡#white⚡#dwarfs⚡#stardust⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels
🪐 The star HD 49798, located about 2,000 light-years away in the constellation Puppis, is an unusual subdwarf that forms a pair with a mysterious, ultra-dense white dwarf companion. The white dwarf is spinning at a record-breaking speed of just 13 seconds per rotation, making it one of the fastest-spinning white dwarfs ever found and offering a glimpse into rare, exotic outcomes of stellar evolution. ✨
#unusualstars⚡#white⚡#dwarfs⚡#HD49798⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels