В прошлом посте говоря "Все вызовы теперь одинаковы" я несколько слукавил. Всё-таки есть в этом зоопарке версий некоторая несовместимость вызов которой просто так не унифицировать. Эти моменты вынесены в отдельный модуль 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 James Webb Space Telescope has observed the galaxy JADES-GS-z7-01-QU, one of the most distant “quiescent” galaxies ever found, meaning it has stopped making new stars even though its light began traveling to us over 13 billion years ago. Seeing JADES-GS-z7-01-QU lets scientists study how some galaxies aged and shut down astonishingly early, offering a rare glimpse into the universe’s remote past when cosmic structures were just beginning to take shape. ✨
#galaxies⚡#distance⚡#telescopes⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels
🪐 The James Webb Space Telescope discovered that the distant galaxy JWST-ER1 has an unexpected bar-shaped structure, even though it formed just 2 billion years after the Big Bang. Bars are elongated collections of stars that stretch across the centers of galaxies, and finding one so early suggests galaxies began organizing themselves much faster than scientists once thought. ✨
#galaxies⚡#telescopes⚡#discovery⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
🪐 Scientists at the SETI Institute have used the Allen Telescope Array to listen for possible signs of alien technology from over 20,000 star systems, including those with known exoplanets like Gliese 581 and Kepler-452. Although no artificial signals have been confirmed, this real-world search for extraterrestrial intelligence uses radio telescopes to scan for narrowband signals—kinds of signals rarely produced by nature, but which could indicate advanced technology elsewhere in the galaxy. ✨
#aliens⚡#radio⚡#telescopes⚡#exoplanets⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels