Когда разрабатываете свой 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
#photo#SouthSudan
The world’s newest country, South Sudan, marked a decade of independence this month, but it’s still one of the world’s poorest nations, scarred by war and hunger.
South Sudan gained independence in 2011, but an intertribal conflict broke out two years later that escalated into a full-blown civil war which has crippled the country’s economy and agriculture.
This Red Cross station in Kobok was the only place where people in South Sudan’s Upper Nile region could get medical help, make phone calls, or simply get something to eat. The Red Cross staff treated all patients equally, regardless of whether they were soldiers or civilians.
Unfortunately, the hospital was destroyed by government forces three weeks after our crew filmed it.
Follow: https://t.me/rtdocumentary
🇨🇳#China - 🇸🇸#SouthSudan: Chinese troops from the 12th Chinese Peacekeeping Infantry Battalion under UNMISS (UN mission in South Sudan) conducted live-fire training in South Sudan last week.
UNMISS has been in the country since 2011 to protect civilians and support stability. The Chinese contingent previously drew major attention after the July 2016 Juba violence, when internal UN findings said Chinese and Ethiopian peacekeepers did not leave their bases to assist civilians despite orders to intervene.
An aid workers’ compound only a few hundred meters from a UN base received no help despite repeated distress calls and a survivor personally reaching the base and pleading for help. Multiple civilians, as well as a journalist, were killed during the clashes at that time.
🇷🇺🇸🇸 The Ambassador of Russia to South Sudan, A.Kosmodemiyanskiy, met with the Minister of Presidential Affairs of South Sudan, Africano Mande Gedima.
🔸 During the friendly and constructive discussion, current issues of bilateral relations were addressed.
🔸A.Kosmodemiyanskiy handed over to the Minister a copy of the personal invitationfrom the President of the Russian Federation, Vladimir Putin, to the President of South Sudan, Salva Kiir Mayardit, to attend the Third Russia-Africa Summit, which will take place in Moscow in October this year.
🔸 Following the meeting, the parties agreed to expand political, economic, and cultural cooperation between the two countries, as well as to arrange training in Russia for staffof the National Elections Commission of South Sudan in preparation for the upcoming presidential elections in December this year.
#Africa#Russia#SouthSudan
Ethiopia, South Sudan To Fast Track Implementing Agreements. Read more.
https://borkena.com/2026/04/26/ethiopia-south-sudan-to-fast-track-implementing-agreements/#Ethiopia#SouthSudan#SouthSudanNews#EthiopianNews#economicintegration#cooperation
Africa Cup of Nations - Qualification🌍
2026-03-29 13:00 UTC
South Sudan vs. Djibouti
Predicted outcome: South Sudan❌
Predicted score: 4:0
Actual: Djibouti 0:1
#SouthSudan#Djibouti
2026-03-29 15:00 UTC
Lesotho vs. Seychelles
Predicted outcome: Draw❌
Predicted score: 0:0
Actual: Lesotho 2:1
#Lesotho#Seychelles
#Football#AfricaCupofNations
Africa Cup of Nations - Qualification🌍
2026-03-26 13:00 UTC
Djibouti vs. South Sudan
Predicted outcome: South Sudan✅
Predicted score: 1:3
Actual: South Sudan 0:4
#Djibouti#SouthSudan
2026-03-26 14:00 UTC
Seychelles vs. Lesotho
Predicted outcome: Lesotho❌
Predicted score: 0:2
Actual: Draw 0:0
#Seychelles#Lesotho
#Football#AfricaCupofNations