В прошлом посте говоря "Все вызовы теперь одинаковы" я несколько слукавил. Всё-таки есть в этом зоопарке версий некоторая несовместимость вызов которой просто так не унифицировать. Эти моменты вынесены в отдельный модуль 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
🪐 Light from the galaxy NGC 4992, located nearly 150 million light-years away in Leo, takes so long to reach us that we observe it as it was when dinosaurs still roamed Earth. Even within our own Milky Way, stars like V404 Cygni are thousands of light-years away, meaning every twinkle in the night sky is a peek deep into the past—a testament to the truly immense distances that fill the universe. ✨
#spacedistances⚡#lightyears⚡#galaxies⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels
🪐 The nearest galaxy to our Milky Way, the Large Magellanic Cloud, is about 163,000 light-years away—which means its light takes 163,000 years to reach us. Even though this galaxy sits relatively close on a cosmic scale, traveling that distance with today’s fastest spacecraft would still take millions of years, revealing just how vast even our local corner of the universe truly is. ✨
#spacedistances⚡#galaxies⚡#lightyears⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
🪐 The Tarantula Nebula, located in the Large Magellanic Cloud about 160,000 light-years from Earth, is so far away that its brilliant glow started traveling toward us when early humans were first learning to use tools. Even within our own galaxy, vast star-forming regions like the Eagle Nebula are thousands of light-years apart—demonstrating that cosmic distances are measured in spans so immense, light itself must journey for tens of thousands of years just to cross them. ✨
#spacedistances⚡#nebulae⚡#lightyears⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels