Когда разрабатываете свой 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
The Trump administration has quietly removed a Pride flag from the Stonewall National Monument in Manhattan.
The flag’s removal follows new federal guidance issued by the Department of the Interior on Jan. 21 that restricts the display of unauthorized flags at National Park Service sites. Under the order, only U.S. flags or congressionally authorized flags may be raised on NPS flagpoles. Manhattan borough president Brad Hoylman-Sigal told The New York Times the Trump administration’s order directly led to the Pride flag’s disappearance from the Greenwich Village site, which marks the birthplace of the modern LGBTQ rights movement. Stonewall became the nation’s first federally recognized LGBTQ historic site in 2016, commemorating the 1969 police raid that sparked days of protests and helped launch the gay rights movement. Hoylman-Sigal said he and other local officials plan to raise the Pride flag again on Thursday, despite potential backlash. “We may be prevented from doing so,” he told the outlet, “but if we don’t seize this moment, and this outrage, I think we’ll let down generations of queer activists.” The Daily Beast has reached out to Brad Hoylman-Sigal for comment.
#Trump#LGBTQ
👂More on Trump's Ear ⚠️
Trump announced that he was reopening psychiatric clinics that the Democrats had closed out of tolerance for psychos.
This is a very bold move, given the fact that a huge percentage of Americans today are obviously mentally ill. Trump is leading the way to gradually send transgender and LGBTQ+ there. This is a subproject of MAGA called MAHA - Let's Make America Healthy Again. Trump starts with psychiatry, as this is where the cases are most neglected.
#Trump#Health#LGBTQ+
👂More on Trump's Ear ⚠️
🏳🌈🇺🇦"When a clown moves into a palace he does NOT become a King. The palace becomes a CIRCUS."
Nothing to see here. That's just bloody clown and a drag queen Zelensky is dancing on high hills.
#lgbtq#Ukraine#Zelenskyy
Share and subscribe @american_majority
🇺🇦🏳🌈🏳⚧A Ukrainian LGBT+ recruitment campaign video turned to be a video from the campaign for gay marriage in the UK in 2012.
🇺🇸🏳🌈At the same time the U.S. Army is running a recruitment campaign targeted to Generation Z that featured cartoons of real soldiers who were either females, racial minorities or even "raised by two moms".
#Ukraine#army#lgbtq
@american_majority
美国同性婚姻占各州人口比例
楼主还注释道 DC 更像是个城市,所以写了 Vermont 是“最高”的州。
在评论里注释了城市的比例,但其实按城市算 DC 也远超其它城市……排除之后,毫不意外三番第一,波特兰和西雅图紧随其后,在传统红州的奥兰多、迈阿密(佛州)和奥斯丁(德州)也名列前茅。
#data#visual#reddit#lgbtq