Когда разрабатываете свой GUI с помощью PyQt для какого-либо софта бывает необходимо позаимствовать цвета из текущего стиля интерфейса. Например, чтобы правильно раскрасить свои виджеты, подогнав их по цвету. Ведь бывает, что ваш GUI используется в разных софтах. Причём некоторые со светлой темой а другие с тёмной.
По умолчанию стили наследуются, но если вы задаёте какую-либо раскраску для части виджета через свой styleSheet, то требуется ссылаться на цвета текущего стиля.
Как это сделать? Как получить нужный цвет из палитры имеющегося стиля? Это достаточно просто, нужно использовать класс QPalette и его роли.
Например, мне нужно достать цвет текста из одного виджета и применить его в другом как цвет фона (не важно зачем именно так, просто захотелось😊).
Получаем палитру виджета и сразу достаём нужный цвет, указав его роль.
from PySide2.QtGui import QPalette
color = main_window.palette().color(QPalette.Text)
теперь можем использовать этот цвет в стилях
my_widget.setStyleSheet(f'background-color: {color.name()};')
Готово, мы динамически переопределили дефолтный стиль используя текущий стиль окна!
На самом деле есть запись покороче, в одну строку и без лишних переменных. Не очень-то по правилам CSS, но Qt это понимает.
my_widget.setStyleSheet('background-color: palette(Text);')
Этот способ не подходит если вам нужно как-то модифицировать цвет перед применением в своих стилях. В этом случае потребуется первый способ.
Зато он прекрасно сработает в файле .qss, то есть не придётся в коде прописывать раскраску отдельных элементов через ссылки на палитру, всё красиво сохранится в отдельном файле .qss!
QListView#my_widget::item:selected {
background: palette(Midlight);
}
Про имеющиеся роли можно почитать здесь🌍
#qt#tricks
🟩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