Когда разрабатываете свой 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
🏆 GuPay Team Cup – 2025 FIFA Club World Cup Edition is LIVE! ⚽️
Choose your team. Power it with every transaction.
From the pitch to the blockchain — this is where Web3 meets real-world passion. ⚽️
🗓 June 9 – July 15, 2025
Support 1 of 32 legendary clubs from the official 2025 FIFA Club World Cup, use GuPay, and help your squad rise to the top!
🎯 How to join:
1️⃣Pick your favorite club by filling out the registration form: link
2️⃣ Make transactions using GuPay throughout the tournament
3️⃣ Each transaction boosts your team’s total score on the leaderboard
🎁 $5,000 Prize Pool
The entire reward will be shared among users who joined the team with the highest total transaction volume via GuPay during the campaign.
📌 Fill the form now to lock in your team choice: link
📊 Team standings and leaderboard will be updated regularly — stay tuned!
🌐 From sport to spending, culture to crypto — Gumart is bringing Web3 to real life, one goal at a time.
#GuPayTeamCup#GuGiveaway
🏆 GuPay Team Cup – FIFA Vibes, $5,000 Prize Pool! 📈
Something big is coming to GuPay... and it’s dressed in jerseys, flags, and fire.✨
⚽️ 32 teams - inspired by the world of FIFA
💥 Fierce competition, full of national pride
💰A massive $5,000 prize pool waiting at the finish line
Choose your team. Make your moves.
Support your side and help them rise to the top.
Can you guess what’s coming? Stay tuned 👀
#GuPayTeamCup#GuGiveaway
🌐 Gumart’s Biggest Global Campaign Ever Is Live – Welcome to Gu Go Global! ✋
This isn’t just another event series - it’s a worldwide Web3 movement.🏅
From the heart of Europe to the soul of Asia, from the energy of the Americas to the innovation of Africa and the heritage of Australia - Gumart is going global, and this time, we’re taking the entire community with us.🎉🏆
And yes, it comes with our biggest giveaway ever.💎
For the first time, users from different continents will unlock exclusive rewards, legendary surprises, and global recognition.📌
This is your chance to represent your region and shine on the world stage. Once-in-a-lifetime perks. 🔼
#GuGlobal#GuGiveaway
Introduce GuEurope: First Giveaway is LIVE! Paris, Here We Come!
We’re giving away 3 VIP Tickets to Paris Blockchain Week - the ultimate Web3 experience in Europe! 🏰
What’s included in the VIP Ticket:
🔼Full access to all main stages & premium sessions
🥳Exclusive networking with top founders, VCs & Web3 leaders
📈Fast-track entry + VIP lounge access
🛍Exclusive VIP Dinner beneath the stunning Pyramide du Louvre.
🏆 How to win?
Climb to the Top 3 of the Europe referral leaderboard during #GuGoGlobal from April 4 to April 8💸
Let’s go, Europe. See you in Paris.
#GuEurope#GuGoGlobal#GuGiveaway
🏆 GuPay Team Cup – The Race Is On! ⚽️
Just 3 days in, and over 2,000 Gumart residents have jumped into the GuPay Team Cup – 2025 FIFA Club World Cup Edition!🚀
🔥 The leaderboard is heating up:
1️⃣ Real Madrid is leading the charge
2️⃣ Chelsea right behind
3️⃣ Manchester City chasing hard!
Want your team to rise? 💥
👉 Every GuPay transaction boosts your team’s score and brings you closer to the $5,000 prize pool!
📍Choose your team now and start transacting: link
#GuPayTeamCup#GuGiveaway#FIFAClubWorldCup