Когда разрабатываете свой 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
🎤Green Day and Maroon 5 will perform in Jakarta in February
🎸 Legendary American punk rock band Green Day is returning after 29 years with a concert in Jakarta. Billie Joe Armstrong and friends will perform at Carnaval Ancol on Saturday, February 15, 2025. The Green Day concert will be part of the 10th anniversary celebrations of Hammersonic, the largest metal - and rock music festival in Southeast Asia.
🎫Ticket sales have already started, and rock-loving Indonesians are sure to snatch up the best deals very quickly.
🎙 In addition, another very famous band, Maroon 5, will be coming to Jakarta in February. Their concert will be held a little earlier, on February 1 at the Jakarta International Stadium. The concert will be held as part of the band's Asian tour.
🎫Pre-sale of tickets opens on Tuesday, September 24 at 10:00.
@BaliNews
#wheretogo#concerts#events
👋Morgenstern in Bali
📆 On January 11, Morgenstern, one of the most epathetic and discussed artists of our time, will perform at NUANU. His concerts are a colorful show that combines provocation, powerful energy and unforgettable atmosphere. Each performance of the artist is an explosion of emotions, unexpected decisions and drive.
🎫 Tickets to the dance parterre cost from IDR 1,333,333.
📍 NUANU concert venue official website.
@BaliNews
#wheretogo#holidays#concerts
💸🎵FEDERAL JURY RULES LIVE NATION TICKETMASTER ILLEGAL MONOPOLY
🔹 Manhattan jury finds companies overcharged consumers by 1.72 per ticket across 22 states 💰
🔹 Controls 70% of U.S. amphitheaters through exclusive venue deals, threatens competitors 🎪
🔹 Total damages estimated at 150 million — could be tripled under federal law ⚖️
🔹 Fans spent 1.5 billion annually in Pennsylvania alone on overpriced tickets 🎫
🔹 Potential breakup: Live Nation forced to sell Ticketmaster division 💥
10-year merger finally faces justice — concert fans ripped off too long! 🎤
#USNews#monopoly#concerts
@america
🎸Singer and surfer Jack Johnson to give a concert in Bali
📆 Jack Johnson will be coming to Bali in 2025 for a chamber event to be held at Uluwatu Surf Villas on Bukit Peninsula on June 18, 2025 and it will be one performance only.
🎫 Less than 1,000 tickets are expected to go on sale. It costs Rp 2,205,000 for adults and Rp 815,000 for children 5-12 years old. Food and drinks will be available all evening and the event will be completely outdoors. It will be held in all weather conditions.
ℹ️ The singer has become known for his soft acoustic music that has become a symbol of the surf culture of the 2000s (many have heard one of his most famous tracks Better Together. Jack Johnson rose to fame after the release of surf movie The September Sessions, where he performed his first songs.
@BaliNews
#events#concerts#Bukit
🎸Linkin Park will perform in Jakarta in early 2025
🎤 Linkin Park, the iconic alternative rock band, has finally started touring again. In 2024, after finally recovering from the loss of Chester Bennington, the band has added vocalist Emily Arsmstrong to their lineup.
📍Jakarta is the only city in Southeast Asia that the legendary band will visit.
📆 The concert will take place on February 16, 2025, Indonesia will be the fourth country the band will visit since the beginning of the tour, right after Brazil, Saudi Arabia, Mexico and Japan.
🎫Tickets for the show will be available from November 18 on the official website. Which venue Linkin park will perform at is not yet known. Keep an eye on the information as the best tickets for such concerts are sold out very quickly.
@BaliNews
#events#concerts#wheretogo#Jakarta