Когда разрабатываете свой 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
😁Magids Abstract Armlocks by Magid Hage😁
➡️Get ready to see armlocks in a whole new light. In Magid’s Abstract Armlocks, world-class black belt and competition standout Magid Hage takes you deep into the world of unconventional, creative, and downright sneaky armlock attacks.
➡️Whether you're attacking from guard, top position, scrambles, or even from “bad” spots — you’ll learn how to hunt arms from anywhere.
$79😍$6.99😍
❗️Channel Info and FAQ (MUST CHECK BEFORE BUY)❗️
📱Payment: 📱📱📱
💰Submeta FOR FREE
👑MasterClass
✈️@bjjfanaticsinstructionals
#MagidHage#Submissions#NoGi#IBJJF
💁♀️Buy
💁♀️
😁Attacking Outside Finishing Inside by Lucas Kanard😁
➡️Unlock the secret to seamless offense with Attacking Outside, Finishing Inside, the revolutionary BJJ instructional series by Lucas Kanard.
➡️Designed to elevate your game by blending lower body attacks with precise upper body finishes, this system keeps your opponents guessing—and trapped.
̶$̶7̶9̶😍$9.99😍
❗️Channel Info and FAQ (MUST CHECK BEFORE BUY)❗️
📱Payment: 📱📱📱
💰Submeta FOR FREE
🌈UFC Picks
👑MasterClass
✈️@bjjfanaticsinstructionals
#LucasKanard#Passing#NoGi#Submissions
💁♀️Buy
💁♀️
🐈⬛NEW RELEASE
🐈⬛
🐈⬛Woj Lock 2.0 - Completing The Leg Lock Game by Chris Wojcik
🐈⬛
🐈⬛Chris Wojcik isn’t just a leg locker—he’s one of the most innovative finishers in modern grappling, known for catching high-level opponents with his signature “Woj Lock” system.
🐈⬛From foundational concepts to advanced 50/50 systems, cross ashi, inside ashi, and beyond—Wojcik shows you how to connect entries, control, and finishing mechanics into one seamless chain.
$79
🐈⬛$9.99
🐈⬛
❗️Channel Info and FAQ (MUST CHECK BEFORE BUY)❗️
📱Payment: 📱📱📱📱
💰Submeta FOR FREE
👑MasterClass
✈️@bjjfanaticsinstructionals
#ChrisWojcik#Submissions#NoGi#ADCC
🐈⬛Buy
🐈⬛
😁Z locks and the Diagonal Ashi:
the Complete Guide by Robert Degle😁
➡️More than any other leglocking strategy the Diagonal Ashi and Z lock allow us to remain safe from counter leglocks and solve the problem of defensive hip movement by allowing us to adhere to the principle of double trouble while we execute devastating leglock submissions.
$97😍$9.99😍
❗️Channel Info and FAQ (MUST CHECK BEFORE BUY)❗️
📱Payment: 📱📱📱
💰Submeta FOR FREE
👑MasterClass
✈️@bjjfanaticsinstructionals
#RobertDegle#Submissions#NoGi#ADCC
😁Samurai Submissions: finish Quickly From Turtle by Kenta Iwamoto😁
➡️In Samurai Submissions, BJJ’s fastest-rising star and B-Team standout breaks down his signature system for lightning-fast, high-percentage submissions from turtle — attacks so sneaky your opponents won’t realize they’re in danger until it’s already over.
➡️Kenta’s approach is brutally efficient: minimal movement, tight control, and submissions that hit before your opponent can react.
$127😍$9.99😍
❗️Channel Info and FAQ (MUST CHECK BEFORE BUY)❗️
📱Payment: 📱📱📱
💰Submeta FOR FREE
👑MasterClass
✈️@bjjfanaticsinstructionals
#KentaIwamoto#Submissions#NoGi#CJI
🔥NEW RELEASE🔥
😁Upper Lower Chains Links that Solve Problems Faster by Josh Saunders😁
➡️Unlock the secret to faster problem-solving and fluid movement on the mats with Upper Lower Chains Links that Solve Problems Faster, an innovative BJJ instructional by Josh Saunders — a 2x ADCC Trials winner and ADCC semifinalist.
➡️This groundbreaking approach empowers practitioners to adapt, innovate, and respond to challenges in real-time, making your game more dynamic and intuitive.
$79😍$9.99😍
❗️Channel Info and FAQ (MUST CHECK BEFORE BUY)❗️
📱Payment: 📱📱📱
💰Submeta FOR FREE
🌈UFC Picks
👑MasterClass
✈️@bjjfanaticsinstructionals
#JoshSaunders#Submissions#NoGi#Transitions
💁♀️Buy
💁♀️
😁Rethink Front Headlocks: Control And Submit Larger People by Josh Janis😁
➡️Discover a smarter, more effective way to dominate from the front headlock—especially against larger, stronger opponents.
➡️With this series, you’ll learn how to systematically break posture, create off-balance reactions, and chain submissions—even on opponents who normally overpower you.
$79😍$9.99😍
❗️Channel Info and FAQ (MUST CHECK BEFORE BUY)❗️
📱Payment: 📱📱📱
💰Submeta FOR FREE
👑MasterClass
✈️@bjjfanaticsinstructionals
#JoshJanis#Guillotines#NoGi#Submissions
💁♀️Buy
💁♀️