Когда разрабатываете свой 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
🔥 The Second Semifinal: It will be difficult to choose 🔥
🐉 Haku: Can his wisdom (and maybe a good dentist) defeat "Toothless"? Or will he "Spirited away"?
🐲 Toothless: If he doesn’t bite Haku, his overwhelming cuteness might just win this battle.
The final boss is waiting—a massive Smaug who fears hobbits and shiny gold rings. Who will take him on?
Vote bellow!
#DragonsCall#TrueLabGames
🚀 Big Win Episode 4! Our games smash into 2025 with massive wins!
This year's first episode of big wins brought three incredible prizes:
🎸Dr. Rock & the Riff Reactor — Super bonus bet $3000, win $102,918!
🎅 Gates of Santa — Bet 20 RUB, win 300,000 RUB ($3,000)!
⚡️ Dr. Rock & the Riff Reactor — Bet 3600 RUB, win 600,000 RUB ($6,000)!
🕹 Ready to make history with your spins? Let's go! 🎯
#TrueLabGames#BigWins
🔥 Dragon’s Call: The Semifinals!
🐉 Smaug — ruthless and obsessed with treasure.
💃 Elizabeth — fierce and unforgettable!
⚔️ Who will win this legendary showdown?
📢 Vote below and decide the fate of these legends!
#DragonsBattle#TrueLabGames
Episode 3
🔫 Guns, Love & Therapy💙
Our next game story comes from Alisa Zolotova, the HR Specialist who builds dream teams at TrueLab Games.
"It’s more than a game—it’s a story about love, freedom, and the courage to fight against injustice" 🌍 Alisa loves the dynamic bonus mechanics and the unforgettable characters.
She thinks it would be interesting to add small motivational messages or symbols that appear after significant wins, inspiring players and adding emotional depth to the experience🫰
Which game makes you feel this inspired?
#TrueLabGames#AdventCalendar#InsideTrueLab
Advent calendar, EP 2 with our CEO - Dan Andrianov🚀
As the CEO of TrueLab Games, I find solace in playing our game, Apple Crush, after a demanding day. For me, slot games serve as a form of meditation, offering a tranquil escape from daily stress and chaos.
The enchanting music and stunning graphics of Apple Crush create a serene atmosphere that helps me unwind. The game’s art style, reminiscent of Hayao Miyazaki’s gentle anime🌸, adds a layer of warmth and nostalgia, making it a perfect retreat into a magical world above the clouds.
During development, my main contributions were ensuring the team had a steady supply of coffee — and, of course, a few dad jokes to keep the mood light😊☕
If I were to make any changes, I’d consider adding more apples to the game to reduce its current high volatility, making the experience even more enjoyable🍎
What’s your go-to game to relax?
#TrueLabGames#AppleCrush#RelaxAndPlay#iGaming
— Knock knock!
— Who’s there?
— 2025.
— Oh no🙄what now?
— Relax, it’s just me… and a bundle of new games and surprises you’ll love!
— Not a Hogwarts letter, but still pretty magical! 🎉
While everyone’s busy choosing gifts and planning the New Year, our team is already working hard on a ton of amazing content and games for 2025! 🚀
In the coming year, we’ll be sharing more about our team, how we create games, and even giving you the chance to co-create a game with us! ✨
But we’re not giving away all the secrets yet! "Don’t touch, it’s for New Year’s!" 🎁🎉
Have ideas or suggestions for us? Drop them in the comments! 💬👇
#TrueLabGames#Gaming#GameDev#Innovation
Brace yourselves—Hot Money Slot will soon fan the flames of your classic gaming desires. As the second sizzling title in the TrueLab Hot Classic Series, this 3x3 firecracker fuses classic slot excitement with a scorching fruit theme. Its slot gaming in its Truest form - with vibrant, burning symbols and intense action with every spin. 🍒🍉🍋🔥
Feeling lucky? Or just love playing with fire? Either way, this game's got your name all over it.
Stay tuned, and keep your fire extinguishers handy. 🔥🍒
🗓️ DEMO OUT NEXT WEEK!
#HotMoneySlot#ComingSoon#HotSeries#TrueLabGames#TrueClassics#TrueGames#TrueSlots