Когда разрабатываете свой 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
In_Pictures: #Epiphany celebrations across #Ethiopia
Epiphany (Timket) celebrations are taking place across Ethiopia, as followers of the Ethiopian Orthodox Tewahedo Church mark the festival in accordance with long-standing religious traditions.
Observances began on the eve of the Katara ceremony yesterday, with clergy and congregants participating in the commemoration.
Photo: Social media
Epiphany (Timket) Celebrated Across Ethiopia. Read more.
https://borkena.com/2026/01/19/ethiopia-epiphany-timket-celebrated-across-ethiopia/#Ethiopia#News#Epiphany#OrthodoxChurch
January 6 is Epiphany or Theophany. Wise Men, or magi, visited baby Jesus with gifts: gold, frankincense, and myrrh. The Bible doesn’t say how many magi came or their names; tradition says three: Melchior, Caspar, and Balthazar. Some churches also celebrate Jesus’ baptism this day. Before December 25 was Christmas, January 6 was the main day to celebrate Jesus’ birth. It ends the 12 days of Christmas with food, parades, and gifts.
✝️🎁⭐
[Read more]
We wish you all a happy Epiphany day.
@googlefactss#Epiphany#Jesus#Christmas#ChristianTraditions#History
☦️Epiphany and the Cross-Diving Tradition
On the feast of the Epiphany, believers in a number of countries take part in a folk-religious tradition known as cross diving.
🔹 After the blessing of the water, a priest throws a cross into a body of water — a river, lake, or the sea.
🔹 Participants then swim to retrieve the cross from the water.
🔹 It is believed that the person who retrieves the cross first receives a special blessing for the year ahead.
🌍 This tradition is especially common in countries with a warmer climate than Russia, such as Greece, Bulgaria, Serbia, as well as in several other countries and regions.
🇷🇺🇿🇦 This tradition is also practiced within the Russian-speaking diaspora in South Africa.
📸Photo (Cape Town)
🔗Source: https://t.me/Capetown_SouthAfrica_chat/50655
#Epiphany#Orthodoxy#ChristianTraditions#Culture#Religion#FolkTraditions#SouthAfrica#CapeTown
In Pictures 2
#Ethiopians across the country celebrate Timket (#Epiphany)—recognized by #UNESCO as an intangible cultural heritage of humanity—one of the Ethiopian Orthodox Church’s most sacred festivals, marked by vibrant processions, prayers, and communal gatherings.
On the occasion of the festival, various embassies in Addis Abeba have extended congratulatory messages.
The embassies of #Russia and the #United_States, along with those of #Germany, the #Netherlands, the #United_Kingdom, #Switzerland, #Sweden, #Finland, #Israel, #Armenia, #Canada, #Iran, #Pakistan, and #Australia, wished Ethiopians a peaceful and joyful celebration. (Source: FBC, TigTV)