Регулярно приходится писать и ревьюить код, где используется PySide2-6.
Заметил, что в подавляющем большинстве случаев настройка создаваемых базовых виджетов происходит через методы. Думаю, всем знаком такой способ.
Простой пример с кнопкой:
button = QPushButton("Click Me")
button.setMinimumWidth(300)
button.setFlat(True)
button.setStyleSheet("font-size: 20pt")
button.setToolTip("Super Button")
button.clicked.connect(lambda: print("Button clicked"))
Но есть и альтернативный способ - настройка через свойства. Это просто ключевые аргументы конструктора класса. Хоть они и не указаны в документации как аргументы, но они есть)
Этот код делает тоже самое но с помощью Property
button = QPushButton(
"Click Me",
minimumWidth=300,
flat=True,
styleSheet="font-size: 20pt",
toolTip="Super Button",
clicked=lambda: print("Button clicked"),
)
Где это может быть полезно
▫️ Это выглядит более аккуратно и коротко, уже повод использовать
▫️ Может использоваться в заполнении лейаута, когда нам не нужно никакое другое взаимодействие с виджетом и поэтому сохранять его в переменную не требуется. Например, лейбл или кнопка.
widget = QWidget(minimumWidth=400)
layout = QHBoxLayout(widget)
layout.addWidget(QLabel("Button >", alignment=Qt.AlignRight))
layout.addWidget(QPushButton("Click Me", clicked=lambda: print("Button clicked")))
widget.show()
Либо так
widget = QWidget(minimumWidth=400)
layout = QHBoxLayout(widget)
for wd in (
QLabel("Button >", alignment=Qt.AlignRight),
QPushButton("Click Me", clicked=lambda: ...)
):
layout.addWidget(wd)
widget.show()
▫️ Можно хранить настройки в каком-то конфиге или генерировать на лету, после чего передавать как kwargs.
kwargs = {"text": "Hello " * 30, "wordWrap": True}
my_label = QLabel(**kwargs)
Как получить полный список доступных свойств?
Эта функция распечатает в терминал все свойства виджета и их текущие значения
def print_widget_properties(widget):
meta_object = widget.metaObject()
for i in range(meta_object.propertyCount()):
property_ = meta_object.property(i)
property_name = property_.name()
property_value = property_.read(widget)
print(f"{property_name}: {property_value}")
#tricks#qt
🟩Let's Share $150,000 in ZETA! zetablockchain
🎯Ready for an immersive experience with #ZetaChain Testnet before the mainnet launch and a chance for potential airdrops?
JOIN NOW 👉https://tp-lab.tptool.pro/tokenpocket-christmas/?locale=en#/ Galxe 👉https://galxe.com/TokenPocket/campaign/GCc28ttYTk
With such incredible projects, the anticipation for the #ZetaChain mainnet is booming! zetaswapdex LENX_Finance zkme_ UltiverseDAO SushiSwap ChatGM_Official CharacterXAI sugar_datingfi eddy_protocol TokenPocket_TP
【Details】https://twitter.com/TokenPocket_TP/status/1746790100393206137
【Powered By】Crypto Box
🆕 ZetaChain Testnet is Now Live on TokenPocket! zetablockchain
▶️Supported by TokenPocket Mobile Wallet and Chrome Extension Wallet!
TokenPocket now supports users to
✅ Custom add #ZetaChain Testnet to TokenPocket.
✅ Create & Import #ZetaChain wallets.
✅ Interact with #ZetaChain Testnet-based DApps.
🚀 Create your first #ZetaChain wallet on TokenPocket_TP!
Use Guide👉https://help.tokenpocket.pro/en/wallet-operation/how-to-create-a-wallet/zetachain-testnet
👉https://www.tokenpocket.pro/
👉https://extension.tokenpocket.pro/#/
【Details】https://twitter.com/TokenPocket_TP/status/1704418412582338967
【Powered By】Crypto Box
🆕#ZetaChain is now live on TokenPocket_TP. zetablockchain
💚ZetaChain is a simple, fast, and secure Omnichain Blockchain.
🚀How to create/import a #ZetaChain wallet on #TokenPocket Mobile Wallet and Chrome Extension Wallet?
Guide👉https://help.tokenpocket.pro/en/wallet-operation/how-to-create-a-wallet/zetachain
Download #TokenPocket
👉https://www.tokenpocket.pro/
👉https://extension.tokenpocket.pro/
#ZetaChain#TokenPocket $ZETA
【Details】https://twitter.com/TokenPocket_TP/status/1752905240133996845
【Powered By】Crypto Box
💥@zetablockchain Ecosystem is booming!!
💚You won't want to miss a chance to share 1,000 #ZETA, right? Dive into👇
https://galxe.com/TokenPocket/campaign/GCEZRtwWpG
🎯How to create & import a #ZetaChain wallet on TokenPocket_TP?
Full guide👇
(For mobile and Chrome extension users.)
【Details】https://twitter.com/TokenPocket_TP/status/1753242729960628260
【Powered By】Crypto Box
💥We’re excited to announce that #TokenPocketChristmas winners can claim rewards at
@ZetaBlockchain
mainnet launch! #ZetaChain
Check if you are on the first-round winner list
👉https://docs.google.com/spreadsheets/d/1zqZx0BHE0gVBn8doFhRAdFBaQrwoxzPbwu2CYCOkvhs/edit#gid=0
How to claim your #ZETA?
1️⃣Download TokenPocket Wallet
👉https://tokenpocket.pro
👉https://extension.tokenpocket.pro
2️⃣Create/import/sync your #ZetaChain wallet on TokenPocket after mainnet launch!
3️⃣Share the news with your friends if you are on the winner list! (RT, Like, Comment) 👉https://twitter.com/TokenPocket_TP/status/1752147092942749951
When to get your ZETA?
⏰The rewards will be distributed at the same time of #ZetaChain airdrop claim opens this week.
All participating user data from #TokenPocket are also whitelisted to get a boost in the first XP campaign on ZetaHub. Learn more about the 10% of the total ZETA token supply for community rewards: https://twitter.com/zetablockchain/status/1750758520637804707
AI Agent Launchpad Goes Live
Zearn launches the world’s first Universal AI Agent launchpad using autonomous AI on ZetaChain’s infrastructure. Users can create meme narratives and deploy AI agents in just three clicks, leveraging real-time social sentiment for refinement. Read more here.
Additionally, Utah's Bitcoin reserve bill has passed the Senate Revenue and Taxation Committee, marking a significant step for cryptocurrency regulation in the state.
#AI#Crypto#Zearn#ZetaChain#Bitcoin#Blockchain#Utah#Innovation
Quoted TokenPocket_TP : 💥All the #TokenPocketChristmas rewards have been distributed to winners' TokenPocket #ZetaChain Wallet!! #HODL
To celebrate the #ZetaChain Mainnet launched, TokenPocket provides 1,000 #ZETA to #TokenPocket users!
Dive into👇
https://galxe.com/TokenPocket/campaign/GCEZRtwWpG#ZetaChain
😁Eligible for TokenPocket users, please create/import a #ZetaChain wallet on #TokenPocket Mobile Wallet and Chrome Extension Wallet?
Guide👉https://help.tokenpocket.pro/en/wallet-operation/how-to-create-a-wallet/zetachain
【Details】https://twitter.com/TokenPocket_TP/status/1752914758746210773
【Powered By】Crypto Box