В прошлом посте говоря "Все вызовы теперь одинаковы" я несколько слукавил. Всё-таки есть в этом зоопарке версий некоторая несовместимость вызов которой просто так не унифицировать. Эти моменты вынесены в отдельный модуль 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
💡 Try something new this school holidays with your kids!
Spring onions are not only a common garnish used to flavour soups and dishes, but they’re also one of the easiest edible plants to grow! No soil or seeds required – all you need are leftover spring onions and a jar of water.
This form of gardening is known as vegetative propagation – the process of growing using parts of the plant other than its seeds. It’s also the perfect opportunity to teach children about sustainability and food security, in line with our #CityinNature vision, and a key pillar of the #SGGreenPlan for sustainable development.
Have fun gardening with your kids! Be sure to snap and share photos of your produce with us in the comments below.
More gardening resources can be found here: www.nparks.gov.sg/gardening/gardening-resources
🏡 Heard of the '80-80-80 in 2030' targets?
🏗 The three targets outlined in the Singapore Green Building Masterplan will help pave the way for a low-carbon built environment; creating healthy, liveable, and sustainable spaces for everyone.
➡️ Read more at: https://go.gov.sg/mndcos-js
#BuildSG#SGGreenPlan
Have an idea on how you can get our community to lead a zero waste lifestyle? Apply for the Call for Ideas Fund to kickstart your project!
Applications close on 7 Nov 2021. To find out more, visit: https://go.gov.sg/callforideasfund
#NEACallforIdeasFund#SayYEStoWasteLess#SGGreenPlan
#DoYouKnow what’s been done to secure our food future?
Visit the “Feeding our Future: Building an Agri-Food Hub for all” exhibition to find out how we are transforming Lim Chu Kang into Singapore’s core agri-food hub, and don’t forget to check out the Farmers’ Market during the opening weekend!
For more info: https://go.gov.sg/feedingourfuture
#30by30#SGGreenPlan
Infographic: Singapore Food Agency (SFA)
Meet Bloobin, our new recycling mascot, who’s on a mission to educate the public on how to #RecycleRight. Read on for more info and recycling tips at www.go.gov.sg/recycleright. Together, let’s work #TowardsZeroWaste and #SaveSemakau! #SGGreenPlan
🌏 What does a cleaner and greener future for Singapore look like to you?
In our Long-Term Plan Review, we are planning a more sustainable future city that is ready for the impacts of climate change.
Share your views on this topic at the World Cities Summit webinar on climate-ready cities on 23 September: go.gov.sg/ltpr-wcs-env
#LTPR2021
#SGTogether#SGGreenPlan
In support of the Ministry of Sustainability and the Environment’s vision for a sustainable, resource-efficient, and climate-resilient Singapore, HDB pledges to be a Champion under the #GreenNationPledgeSG!
We will continue efforts to reduce energy consumption and carbon footprint in our operations.
🔗 Join us in submitting a pledge
Together, let’s support Singapore in becoming a Green Nation! 💚
#ForwardSG#SGGreenPlan
#PSA To support the take-up of electric cars, we're extending the Vehicular Emissions Scheme until 31 Dec 2027. From 1 Jan 2026, only fully electric vehicles will qualify for rebates. 🔗go.gov.sg/nea-ves
#SustainableSG#SGGreenPlan#CleanAirForAll
Images generated using Adobe Firefly.