Когда разрабатываете свой 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
🚀 Thailand's Central Bank Governor Projects GDP Growth for 2026
Thailand's Central Bank Governor has projected the country's GDP growth rate to be between 1.3% and 1.7% in 2026. According to Jin10, this forecast reflects the economic outlook for Thailand as it navigates various domestic and international challenges. The central bank's projection aims to provide guidance for policymakers and investors as they plan for the future economic landscape.
#Thailand#CentralBank#GDPgrowth#economicoutlook #2026 #policy#investors
🚀 Indonesia's Central Bank Projects 5.2% GDP Growth in Q1
Indonesia's central bank has projected a GDP growth rate of 5.2% for the first quarter, according to Jin10. This forecast reflects the country's economic outlook as it navigates various domestic and international challenges. The central bank's projection aligns with efforts to maintain economic stability and growth amid global uncertainties. The anticipated growth rate is seen as a positive indicator for Indonesia's economic performance in the early part of the year.
#Indonesia#CentralBank#GDPGrowth#EconomicForecast#Q12026#EconomicStability#GlobalEconomy#EconomicOutlook
🚀 AI TRENDS | Faster AI Progress May Impact U.S. Labor Force Participation by 2050
A recent study conducted by multiple universities suggests that accelerated advancements in artificial intelligence could significantly affect U.S. labor force participation. According to NS3.AI, the research predicts a decline from 62% to 54% by 2050 under a rapid AI development scenario. This scenario also anticipates an annual GDP growth rate of 3.5% between 2045 and 2049. The focus of the debate has shifted to whether AI will generate sufficient new employment opportunities to counterbalance the displacement of existing jobs.
#AI#AItrends#USlaborforce#AIdisplacement#GDPgrowth#laborforceparticipation #2050 #futureofwork
🚀 Middle East Conflict Could Severely Impact Australia's Economy, Expert Warns
Calculations and analyses are currently underway regarding the potential impact of the ongoing Middle East conflict on Australia's fuel prices and economic growth. According to Jin10, David Rumbens, a partner at Deloitte Access Economics, has stated that the worst-case scenario would severely affect Australia. A prolonged conflict could drive oil prices up to $175 per barrel, with inflation rates reaching 7.5% by the end of the year. The ultimate outcome could see Australia's unemployment rate rise to 6.8%, while the GDP growth rate could decline by 2.8%. Notably, none of the proposed scenarios indicate an unemployment rate below 5.0%.
#MiddleEastConflict#AustraliaEconomy#FuelPrices#EconomicGrowth#Inflation#Unemployment#GDPGrowth#OilPrices#DavidRumbens#DeloitteAccessEconomics
🚀 Austrian Economic Institutes Lower Growth Forecasts Amid Iran Conflict Impact
On April 10, two major Austrian economic research institutes announced that the ongoing conflict in Iran is threatening Austria's economic recovery in 2026. According to Jin10, the Institute for Advanced Studies (IHS) has revised its growth forecast for Austria's economy in 2026 down to 0.5% and in 2027 to 0.8%, from previous estimates of 1.0% and 1.1%, respectively. The revision is attributed to soaring energy prices and increased uncertainty.
Similarly, the Austrian Institute of Economic Research (WIFO) has adjusted its GDP forecast, projecting growth between 0.2% and 1.1% for 2026, and between 0.4% and 1.5% for 2027, down from earlier predictions of 1.2% and 1.4%. WIFO noted that the current uncertain international environment complicates forecasting efforts.
WIFO also anticipates Austria's inflation rate to range between 2.5% and 4.1% in 2026, and between 2.2% and 3.5% in 2027. Meanwhile, IHS forecasts this year's inflation rate at 2.9%, with a decrease to 2.4% in 2027.
#Austria#economicforecast#Iranconflict#energyprices#GDPgrowth#inflation#IHS#WIFO#economicrecovery#2026growth#2027forecast#internationaluncertainty