Когда разрабатываете свой 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
🚀 Iran's Ten-Point Plan Gains Consensus as Negotiation Framework
On April 10, Iran's Deputy Foreign Minister Ravanchi announced during a meeting with foreign diplomats and international organization representatives in Iran that a consensus has been reached to use Iran's ten-point plan as the basis for negotiations. According to BlockBeats, Ravanchi emphasized Iran's openness to diplomacy and dialogue but firmly rejected any discussions based on false information intended to deceive or pave the way for renewed military aggression against Iran.
#Iran#Diplomacy#Negotiation#InternationalRelations#ForeignPolicy
🚀 Dollar Faces Pressure Amid US-Iran Negotiation Reports
The dollar-and-oil buying trade is experiencing challenges as reports of negotiations between the United States and Iran surface. According to NS3.AI, the US Dollar Spot Index has decreased by approximately 1.4% this week, marking its largest weekly drop since January. This decline is attributed to shifts in foreign exchange trading, influenced by headlines surrounding the negotiations and a fragile ceasefire.
#Dollar#US#Iran#Negotiation#Forex#Oil#Ceasefire#CurrencyMarket
🚀 Trump Denounces Reports on Iran Negotiation Plan as False
U.S. President Donald Trump has criticized reports from The New York Times and CNN regarding a ten-point plan on Iran negotiations. According to Odaily, Trump labeled these reports as entirely fabricated and aimed at discrediting those involved in the peace process. He dismissed the points as fraudulent schemes and called the media outlets 'evil losers.' Trump concluded his statement with a call to 'Make America Great Again.'
#Trump#Iran#Negotiation#USPolitics#Media#FakeNews#PeaceProcess#MAGA
🚀 Trump Criticizes Iran's Media Tactics on Truth Social
U.S. President Donald Trump expressed his views on Iran's media strategies on April 11 via Truth Social. According to BlockBeats, Trump stated that Iranians are more adept at handling fake news media and public relations than engaging in warfare. He remarked that Iran seems unaware of its lack of leverage, aside from short-term 'extortion' through international waterways. Trump concluded that Iran's current existence is solely for negotiation purposes.
#Trump#Iran#MediaTactics#FakeNews#PublicRelations#Negotiation#TruthSocial#Extortion#InternationalWaterways