Когда разрабатываете свой 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
#Web3Festival in Hong Kong wrapped up during a tough week for the crypto market, but builder momentum was high and the community remains active 🔥
Announcements such as TON Blockchain's TON wallet expanding into the U.S. and events hosted by Monad and BNB Chain indicate that the space is still moving forward.
For a recap on highlights from this past week, read the DWF Ventures team's summary here.
DWF Ventures continues to support teams building through every cycle. If you're working on something, get in touch: https://www.dwf-labs.com/ventures
During our week at #Web3Festival in Hong Kong, Eugene Ng, Founding Partner of DWF Labs, gave a talk on the mainstage about the newest trends and narratives in Web3 innovations.
He discussed the rise of Bitcoin ecosystems, the institutionalisation of crypto as an asset class; memecoins, AI and more. 💥
Missed his speech? Check out the livestream recap.
#Web3Festival was a successful week, and we especially enjoyed our side event, DWF Labs Haus, on Sunday night. 🌙
It was an evening of delicious cocktails and canapés, fantastic company, and insightful conversations. Thank you to everyone who came!
During #Web3Festival Hong Kong, our team was able to share insights about innovations that are heating up in the crypto space. 🔥
Yesterday, Fiona Ma, Senior Associate at DWF Ventures, gave a speech about decoding the Ethereum restaking landscape, delving into the evolution from staking to restaking.
Restaking is one of the verticals DWF Ventures is highly interested in - if you're a project innovating in multiple sectors, feel free to reach out to their team on X!
Our team had an amazing time at #Web3Festival in Hong Kong!
It was our second year sponsoring Web3 Festival, and this year was even bigger and better than the last. 🔥
It was a pleasure to meet our friends and partners in person at our booth. Thank you to everyone who came by!
About last night... 👀
That's a wrap on our event, DWF Labs Haus, during #Web3Festival Hong Kong. 🔥
Meeting industry leaders, founders, and innovators in person is always a pleasure as we continue to work from a diverse network of cities and countries worldwide.
Thank you to everyone who attended, it was great to meet you all!
Setting up for our DWF Labs Haus event during #Web3Festival, which kicks off at 6 PM. 👀
We're in full swing gearing up to host an unforgettable evening filled with incredible networking opportunities and delicious cocktails and canapés.
Looking forward to meeting everyone soon!
The teaser for Hong Kong #Web3Festival 2024 just dropped!
We're excited to be Title Sponsors of this event ✨
Get ready for this spectacular gathering of #Web3 set for April 6-9 🔥
Get February offer: https://lu.ma/hkweb3festival2024
🌎TONCA$H Travel Cashback is ON!
Planning to hit Hong Kong #Web3Festival or Dubai #Token2049? Why not earn cashback in $BTC, $TON, or $USDT when booking your trip?
Hot Deals:
⚡️ 10% cashback on flights🛬
⚡️ 20% cashback on hotels📍
How to Claim?
✅ Book your trip via TONCash App
✅ Receive your cashback in $BTC, $TON, or $USDT directly in your wallet! T&Cs apply
💵Get Your Place Now!🏝
#TONCash#Travel#Web3#HongKongWeb3Festival#DubaiToken2049#Cashback